Skip to content

Fix a crash on missing self with --check-untyped-defs #7669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def function_type(func: FuncBase, fallback: Instance) -> FunctionLike:
def callable_type(fdef: FuncItem, fallback: Instance,
ret_type: Optional[Type] = None) -> CallableType:
# TODO: somewhat unfortunate duplication with prepare_method_signature in semanal
if fdef.info and not fdef.is_static:
if fdef.info and not fdef.is_static and fdef.arg_names:
self_type = fill_typevars(fdef.info) # type: Type
if fdef.is_class or fdef.name() == '__new__':
self_type = TypeType.make_normalized(self_type)
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -6319,3 +6319,10 @@ class Foo:
reveal_type(Foo().x) # N: Revealed type is 'Union[Any, None]'
reveal_type(Foo().y) # N: Revealed type is 'builtins.list[Any]'
[builtins fixtures/list.pyi]

[case testCheckUntypedDefsSelf3]
# flags: --check-untyped-defs

class Foo:
def bad(): # E: Method must have at least one argument
self.x = 0 # E: Name 'self' is not defined