Skip to content

Commit

Permalink
Merge pull request #523 from pypa/feature/keyword-only
Browse files Browse the repository at this point in the history
Remove no_positional.
  • Loading branch information
jaraco authored Nov 10, 2019
2 parents 109bddc + 28accfa commit 485f657
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 53 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
=========
Changelog
=========
* :feature:`520`: Remove ``no_positional`` decorator in favor of native
syntax.
* :feature:`518` Add Python 3.8 to classifiers.
* :bug:`332` More robust handling of server response in ``--skip-existing``
* :release:`2.0.0 <2019-09-24>`
Expand Down
24 changes: 0 additions & 24 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,30 +368,6 @@ def test_get_password_runtime_error_suppressed(
assert 'fail!' in str(warning)


def test_no_positional_on_method():
class T:
@utils.no_positional(allow_self=True)
def __init__(self, foo=False):
self.foo = foo

with pytest.raises(TypeError):
T(1)

t = T(foo=True)
assert t.foo


def test_no_positional_on_function():
@utils.no_positional()
def t(foo=False):
return foo

with pytest.raises(TypeError):
t(1)

assert t(foo=True)


@pytest.mark.parametrize('repo_url', [
"https://pypi.python.org",
"https://testpypi.python.org"
Expand Down
2 changes: 1 addition & 1 deletion twine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Settings:
Settings(sign=True, username='fakeusername')
"""

@utils.no_positional(allow_self=True)
def __init__(self,
*,
sign=False, sign_with='gpg', identity=None,
username=None, password=None,
comment=None,
Expand Down
28 changes: 0 additions & 28 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,31 +287,3 @@ def get_password(system, username, cli_value, config):
username,
),
)


def no_positional(allow_self=False):
"""A decorator that doesn't allow for positional arguments.
:param bool allow_self:
Whether to allow ``self`` as a positional argument.
"""
def reject_positional_args(function):
@functools.wraps(function)
def wrapper(*args, **kwargs):
allowed_positional_args = 0
if allow_self:
allowed_positional_args = 1
received_positional_args = len(args)
if received_positional_args > allowed_positional_args:
function_name = function.__name__
verb = 'were' if received_positional_args > 1 else 'was'
raise TypeError(('{}() takes {} positional arguments but {} '
'{} given').format(
function_name,
allowed_positional_args,
received_positional_args,
verb,
))
return function(*args, **kwargs)
return wrapper
return reject_positional_args

0 comments on commit 485f657

Please sign in to comment.