Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mypy-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Nov 10, 2019
2 parents 04cdc41 + 485f657 commit e4ddbbc
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 54 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
1 change: 1 addition & 0 deletions twine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Settings:
@utils.no_positional(allow_self=True)
def __init__(
self,
*,
sign: bool = False,
sign_with: Optional[str] = 'gpg',
identity: Optional[str] = None,
Expand Down
30 changes: 0 additions & 30 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,33 +339,3 @@ def get_password(
username,
),
)


# TODO: Replace this with Python 3 keyword-only arguments
# See https://github.com/pypa/twine/issues/520
def no_positional(allow_self: bool = False) -> Callable:
"""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 e4ddbbc

Please sign in to comment.