-
Notifications
You must be signed in to change notification settings - Fork 105
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
NamedTuple subclass class objects do not pass check_argument_types for "Type[BaseClass]" #249
Comments
How am I supposed to get the type information to pass these? The superclasses don't show up in either |
That's a good question. I'm not sure; you can introspect that it's a namedtuple by checking Checking the parent hierarchy is where it gets weird: In 3.7, I don't think you can do this. This line seems to effectively strip out the real class hierarchy such that a brand new NamedTuple gets constructed. In py3.9+ (via this PR), I think this information is preserved in If indeed this works on 3.9+, what would you think about adding this to |
The example script does not run at all on Python 3.10 ( |
If they fixed the ability to even do this at all in 3.10, then yep, this should be considered resolved! Sorry for the issue-report noise, I only had a Py3.7 environment to test against so wasn't aware of the new fixes for this pattern as a whole. |
Describe the bug
Given a parent class "Foo" and a subclass "Bar" which also subclasses NamedTuple,
typeguard
fails to validate "Bar" for the annotationType[Foo]
.To Reproduce
Expected behavior
All three test calls should pass.
Additional context
Subclassing NamedTuple is dicey and not recommended, but it works OK if your superclass doesn't add any fields (just behavior), so this is a semi-reasonable use case.
The text was updated successfully, but these errors were encountered: