Skip to content
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

MyPy does not consider classes instances of their metaclass #1267

Closed
wittekm opened this issue Mar 3, 2016 · 6 comments
Closed

MyPy does not consider classes instances of their metaclass #1267

wittekm opened this issue Mar 3, 2016 · 6 comments

Comments

@wittekm
Copy link
Contributor

wittekm commented Mar 3, 2016

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.)

@JukkaL JukkaL added the feature label Mar 17, 2016
@gvanrossum gvanrossum added this to the Future milestone Apr 7, 2016
@Diggsey
Copy link

Diggsey commented Jul 4, 2016

This is problematic with Enums, because enums have the __members__ property on their metaclass. Annoyingly it can't be faked by adding a __members__ field to the enum class itself, because it gets retyped by mypy as though it were a variant of the enum.

@gvanrossum
Copy link
Member

Another curious case where this is problematic: ctypes defines classes (e.g. c_char) that can be multiplied (e.g. c_char*16 is an array of 16 bytes).

@ilevkivskyi
Copy link
Member

This issue seems to be fixed by #2475 (but only with python 3 syntax, metaclass=AsdfMeta). The first function call passes. two other fail.

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 7, 2017

Updated priority since it looks like this should be easier to fix now that #2475 has landed.

@gvanrossum
Copy link
Member

Looks like this is now fixed (in master). I get the last two errors (which seem expected) but this line is now error-free in the example:

accepts_an_asdf_class(AsdfConcrete1)

@wittekm
Copy link
Contributor Author

wittekm commented Feb 7, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants