Skip to content

class decorator could change type of the decorated class #7614

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
ZeeD opened this issue Oct 3, 2019 · 2 comments
Closed

class decorator could change type of the decorated class #7614

ZeeD opened this issue Oct 3, 2019 · 2 comments

Comments

@ZeeD
Copy link

ZeeD commented Oct 3, 2019

Can a class decorator "change" the type of the decorated class?
My issue is with a "wrapper" class that I created, but I can replicate with even this example:

@str
class C: ...
reveal_type(C)

if I launch mypy I see

$ mypy <(echo '@str
> class C: ...
> reveal_type(C)')
/dev/fd/63:3: note: Revealed type is 'def () -> __main__.C'
$

while C, actually, has became a str!

@msullivan
Copy link
Collaborator

Yeah, we basically don't do any typechecking of class decorators at all. This is definitely a bug (and a duplicate of #3135) but mostly it hasn't seemed to be a problem!

I think it is somewhat unlikely we will ever understand complicated class decorator behaviors, but we could certainly do better here. I think we'd be more likely to just reject this call than to turn C into a variable of type str, though.

@ZeeD
Copy link
Author

ZeeD commented Oct 4, 2019

Sorry for the duplicate, I couldn't find similar issues.
As I said, the "str" was just a "minimal reproducible example", my original problem was with a "wrapper class that act as a replacement".
By the way, I remember to have seen (in a private repo) code with a "singleton" decorator that basically instantiated the class

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

2 participants