Skip to content

Error when dynamically constructing classes from reflected metaclass #7086

Closed
@PeterJCLaw

Description

@PeterJCLaw

In the following code, the presence of the last line (the call to foo_meta) causes mypy to emit an error without a line number and which cannot be ignored.

class FooMeta(type):
    pass
class Foo(metaclass=FooMeta):
    pass

foo_meta = type(Foo)
reveal_type(foo_meta)  # shows: Revealed type is 'Type[def () -> foo.Foo]'

foo_meta("Bar", (Foo,), {})

The error is:

foo.py: error: Unsupported type Type["Type[Foo]"]

I would expect that even if mypy were unable to determine the types here I would be able to ignore the error with a suitably placed # type: ignore (instead I get a warning about an unused ignore). Ideally the usage wouldn't error at all though.

Python: 3.5.2
mypy: 0.701 (verified still an issue under 0.711, the latest at the time of writing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions