Skip to content

Not enough type inference in __init__ with --check-untyped-defs #7309

Closed
@colinfang

Description

@colinfang

mypy v0.720

using --check-untyped-defs

class Foo: pass

class A:
    def __init__(self) 
        self.f1 = Foo()
       # Any
        reveal_type(self.f1)

        self.f2: Foo = Foo()
        # Foo
        reveal_type(self.f2)

class B:
    def __init__(self) -> None:
        self.f1 = Foo()
       # Foo
        reveal_type(self.f1)

I would expect --check-untyped-defs would make A behave like B. However, some type inference seems missing if __init__ is not annotated.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions