Replies: 2 comments 5 replies
-
That seems extremely specific and unusual and I don't think any type system would provide a feature to do this. The closest you can come is writing a child class |
Beta Was this translation helpful? Give feedback.
4 replies
-
Doesn't PEP 696 – Type defaults for TypeVarLikes effectively address this? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
(Typing not-quite-novice, but possibly intermediate, here.; cross-post from SO.)
I know that I can have a generic parent class and child class, like this:
Now let's say I have many child classes,
Child2
,Child3
, etc, which all inherit fromParent[T]
. Inside of my_module.py, I can give them all typing information like this:But what I would like to do is tell the type checker that in my_module, ALL of the instances that are from child classes of
Parent
should havemember_x
the type,float
, and then just write the code ignoring typing syntax after that, like so:Can I do it? Or is this just a dumb thing to want to do?
Beta Was this translation helpful? Give feedback.
All reactions