Making a dictionary covariant, or some other way to type an old pattern #1261
Unanswered
DanielNoord
asked this question in
Q&A
Replies: 0 comments
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.
Uh oh!
There was an error while loading. Please reload this page.
-
I know you can't make a dictionary covariant and it's probably impossible to type the following pattern correctly but I thought it wouldn't hurt to ask.
We have the following simplified pattern:
Basically, I want
add_function_2
to produce an error. In layman terms thefunction_pairs
dictionary should behave as follows:Store a key-value pair for every type of the subclasses of
Parent
where every value is a list of functions that only accept an instance of the type of the key.Can you type this in Python? Or this code so un-typesafe that it is not expressible?
Beta Was this translation helpful? Give feedback.
All reactions