Skip to content

Commit c6efeab

Browse files
authored
Fix a crash on missing self with --check-untyped-defs (#7669)
1 parent 7c43cf9 commit c6efeab

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mypy/typeops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def function_type(func: FuncBase, fallback: Instance) -> FunctionLike:
400400
def callable_type(fdef: FuncItem, fallback: Instance,
401401
ret_type: Optional[Type] = None) -> CallableType:
402402
# TODO: somewhat unfortunate duplication with prepare_method_signature in semanal
403-
if fdef.info and not fdef.is_static:
403+
if fdef.info and not fdef.is_static and fdef.arg_names:
404404
self_type = fill_typevars(fdef.info) # type: Type
405405
if fdef.is_class or fdef.name() == '__new__':
406406
self_type = TypeType.make_normalized(self_type)

test-data/unit/check-classes.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6319,3 +6319,10 @@ class Foo:
63196319
reveal_type(Foo().x) # N: Revealed type is 'Union[Any, None]'
63206320
reveal_type(Foo().y) # N: Revealed type is 'builtins.list[Any]'
63216321
[builtins fixtures/list.pyi]
6322+
6323+
[case testCheckUntypedDefsSelf3]
6324+
# flags: --check-untyped-defs
6325+
6326+
class Foo:
6327+
def bad(): # E: Method must have at least one argument
6328+
self.x = 0 # E: Name 'self' is not defined

0 commit comments

Comments
 (0)