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

cannot inherit from a parameters #14185

Closed
samsja opened this issue Nov 25, 2022 · 4 comments
Closed

cannot inherit from a parameters #14185

samsja opened this issue Nov 25, 2022 · 4 comments
Labels
bug mypy got something wrong

Comments

@samsja
Copy link

samsja commented Nov 25, 2022

Bug Report

It seems that mypy does not allow to inherit from a parameter when creating a function on the fly.

To Reproduce

from typing import Type


def f(cls: Type) -> Type:


    class A(cls):
        ...
    
    return A

>>>file.py:6: error: Variable "cls" is not valid as a type  [valid-type]
>>>file.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
>>>file.py:6: error: Invalid base class "cls"  [misc]

Expected Behavior

Mypy should not complain

Actual Behavior

Mypy complain and say

>>>file.py:6: error: Variable "cls" is not valid as a type  [valid-type]
>>>file.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
>>>file.py:6: error: Invalid base class "cls"  [misc]

Your Environment

  • Mypy version used:`0.990
  • Python version used: 3.9.10
@samsja samsja added the bug mypy got something wrong label Nov 25, 2022
@tmke8
Copy link
Contributor

tmke8 commented Nov 25, 2022

I believe that's fixed by #14135 which has been merged to master but hasn't been released yet.

(I haven't tried it out though.)

@AlexWaygood
Copy link
Member

I believe that's fixed by #14135 which has been merged to master but hasn't been released yet.

(I haven't tried it out though.)

Correct, this is already fixed on master. I can reproduce with c660354, but not with 3c5f368. The fix will be released as part of mypy 1.0, coming soon!

@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2022
@samsja
Copy link
Author

samsja commented Nov 25, 2022

Just tried with this version it work indeed. Thanks for the amazing work !

@AlexWaygood
Copy link
Member

Just tried with this version it work indeed. Thanks for the amazing work !

You have @ilevkivskyi to thank :)

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

No branches or pull requests

3 participants