Skip to content

MyPy does not consider classes instances of their metaclass #1267

Closed
@wittekm

Description

@wittekm

Playing around with a toy situation as below:

class AsdfMeta(type): pass
class AsdfConcrete1(object):
  __metaclass__ = AsdfMeta

def accepts_an_asdf_class(klass): # type: (AsdfMeta) -> None
  pass

accepts_an_asdf_class(AsdfConcrete1)
accepts_an_asdf_class(AsdfConcrete1())
accepts_an_asdf_class("hello, i am a string and not a class with metaclass AsdfMeta")

I get back

56: error: Argument 1 to "accepts_an_asdf_class" has incompatible type "AsdfConcrete1"; expected "AsdfMeta"
57: error: Argument 1 to "accepts_an_asdf_class" has incompatible type "AsdfConcrete1"; expected "AsdfMeta"
58: error: Argument 1 to "accepts_an_asdf_class" has incompatible type "unicode"; expected "AsdfMeta"

(This is super low-priority in my opinion.)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions