Skip to content

self.__class__ is Any, unless I annotate __init__, in which case it is "type" #4065

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

Closed
douglas-treadwell opened this issue Oct 5, 2017 · 2 comments

Comments

@douglas-treadwell
Copy link

douglas-treadwell commented Oct 5, 2017

Wouldn't it be better if the type of self.class was the current class?

`class Class(object):
attr = None

def __init__(self):
    # type: () -> None
    reveal_type(self.__class__)
    print(self.__class__.attr)

`

This way, the revealed type is:
Revealed type is 'builtins.type'

If I remove the # type annotation, the revealed type is:
Revealed type is 'Any'

@JelleZijlstra
Copy link
Member

See python/typeshed#1549, which we'll hopefully reapply at some point.

@gvanrossum
Copy link
Member

Also, the Any result is because without the annotation it's an untyped function. Newer mypy versions earn about reveal_type() in that context.

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

No branches or pull requests

3 participants