Merge pull request #2432 from agronholm/kwonlyargs

#2432 Fix unwanted * between varargs and keyword only args
This commit is contained in:
Takayuki SHIMIZUKAWA 2016-10-19 00:54:38 +09:00 committed by GitHub
commit 340c6fb9f4
3 changed files with 16 additions and 7 deletions

View File

@ -369,7 +369,9 @@ def formatargspec(function, args, varargs=None, varkw=None, defaults=None,
formatted.append('*' + format_arg_with_annotation(varargs))
if kwonlyargs:
formatted.append('*')
if not varargs:
formatted.append('*')
for kwarg in kwonlyargs:
arg_fd = StringIO()
arg_fd.write(format_arg_with_annotation(kwarg))

View File

@ -1052,14 +1052,17 @@ def test_type_hints():
# Keyword-only arguments
verify_arg_spec(f5, '(x: int, *, y: str, z: str) -> None')
# Keyword-only arguments with varargs
verify_arg_spec(f6, '(x: int, *args, y: str, z: str) -> None')
# Space around '=' for defaults
verify_arg_spec(f6, '(x: int = None, y: dict = {}) -> None')
verify_arg_spec(f7, '(x: int = None, y: dict = {}) -> None')
# Callable types
verify_arg_spec(f7, '(x: typing.Callable[[int, str], int]) -> None')
verify_arg_spec(f8, '(x: typing.Callable[[int, str], int]) -> None')
# Tuple types
verify_arg_spec(f8, '(x: typing.Tuple[int, str],'
verify_arg_spec(f9, '(x: typing.Tuple[int, str],'
' y: typing.Tuple[int, ...]) -> None')
# Instance annotations

View File

@ -35,16 +35,20 @@ def f5(x: int, *, y: str, z: str) -> None:
pass
def f6(x: int = None, y: dict = {}) -> None:
def f6(x: int, *args, y: str, z: str) -> None:
pass
def f7(x: Callable[[int, str], int]) -> None:
def f7(x: int = None, y: dict = {}) -> None:
pass
def f8(x: Callable[[int, str], int]) -> None:
# See https://github.com/ambv/typehinting/issues/149 for Callable[..., int]
pass
def f8(x: Tuple[int, str], y: Tuple[int, ...]) -> None:
def f9(x: Tuple[int, str], y: Tuple[int, ...]) -> None:
pass