diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index ebb48c0640d2b..660ca31416a4a 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -307,10 +307,11 @@ def get_annotation(key: str) -> str | None: arglist: list[ArgSig] = [] # Add the arguments to the signature - def add_args(args, get_default_value: Callable[[int, str], object | None]): + def add_args(args: list[str], get_default_value: Callable[[int, str], object | None]) -> None: for i, arg in enumerate(args): # Check if the argument has a default value - if default_value := get_default_value(i, arg): + default_value = get_default_value(i, arg) + if default_value is not None: if arg in annotations: argtype = annotations[arg] else: @@ -325,7 +326,7 @@ def add_args(args, get_default_value: Callable[[int, str], object | None]): else: arglist.append(ArgSig(arg, get_annotation(arg), default=False)) - def get_pos_default(i: int, _arg: str) -> object | None: + def get_pos_default(i: int, _arg: str) -> Any | None: if defaults and i >= len(args) - len(defaults): return defaults[i - (len(args) - len(defaults))] else: @@ -340,7 +341,7 @@ def get_pos_default(i: int, _arg: str) -> object | None: elif kwonlyargs: arglist.append(ArgSig("*")) - def get_kw_default(_i: int, arg: str) -> object | None: + def get_kw_default(_i: int, arg: str) -> Any | None: if kwonlydefaults: return kwonlydefaults.get(arg) else: diff --git a/mypy/test/teststubgen.py b/mypy/test/teststubgen.py index bf2f814942501..71bbbc5d9420b 100644 --- a/mypy/test/teststubgen.py +++ b/mypy/test/teststubgen.py @@ -845,10 +845,9 @@ class TestClassVariableCls: assert_equal(gen.get_imports().splitlines(), ["from typing import ClassVar"]) assert_equal(output, ["class C:", " x: ClassVar[int] = ..."]) - def test_non_c_generate_signature_with_kw_only_args(self) -> None: class TestClass: - def test(self, arg0, *, keyword_only : str, keyword_only_with_default : int = 7): + def test(self, arg0: str, *, keyword_only: str, keyword_only_with_default: int = 7) -> None: pass output: list[str] = [] @@ -869,7 +868,7 @@ def test(self, arg0, *, keyword_only : str, keyword_only_with_default : int = 7) assert_equal( output, [ - "def test(self, arg0, *, keyword_only: str, keyword_only_with_default: int = ...): ..." + "def test(self, arg0: str, *, keyword_only: str, keyword_only_with_default: int = ...): ..." ], )