Generic nested classes #7992
Unanswered
BaconPancakes
asked this question in
Q&A
Replies: 1 comment
-
This code won't type check because you've created a circularity. Resolving the type of The code also redefines I've seen other people try to use this design pattern, and it doesn't work well with static type checking. If you want your code to work well with static typing, I recommend exploring alternatives. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I currently have the following:
I want to achieve an interface that users can implement while also allowing them to specify a user-defined class to use as an argument to
my_fun
.However, it would be nice if I could nest FooHelper from within Foo somehow to avoid having to have loose classes (FooHelper, BarHelper, BobHelper) since many of these could live in the same module.
So, somehow:
I think what I'm looking for is to have a generic nested Class type bound to the parent class.
This StackOverflow answer seems to have an idea but it doesn't type check in pyright so I'm not sure if it's sound.
Code sample in pyright playground
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions