Skip to content
Discussion options

You must be logged in to vote

IIRC the type you get within an instance is not quite the same as the one you get from specifying the type parameters on a generic, since calling __getitem__ on a generic gives you a _GenericAlias back, which behaves like the original type for many use cases, since the original class gets inserted into its mro, but is not the actual type. get_origin and get_args only return something on a _GenericAlias and not the unbound generic type. __orig_bases__ looks correct to me. So I don't think SomeModel gets erased.

Why not just pass in the type as an additional parameter? It seems more readable to me anyways i.e.:

class GenericTestCaseLoader:
    @classmethod
    def load_test_case(cls, model: t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@justinturpin
Comment options

Answer selected by justinturpin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants