Skip to content

Generics Issue with a Base Class Deriving from Table: AttributeError: type object 'AppModel' has no attribute '__parameters__' #1136

Answered by sinisaos
pavdwest asked this question in Q&A
Discussion options

You must be logged in to vote

@pavdwest I'm far from an expert, but I don't think it has anything to do with Piccolo. Shouldn't creation of generics be like this

from typing import Generic, TypeVar, Type, get_args

# Base Model
class AppModel(Generic[CreateDTOType, ReadDTOType], Table):
   ...

async def main():
    # check at runtime
    print(get_args(AppModel.__orig_bases__[0])) # result is (~CreateDTOType, ~ReadDTOType)
    ...

That way type hinting works correctly and you can check generics at runtime. Sorry if I'm wrong.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@sinisaos
Comment options

Answer selected by pavdwest
@pavdwest
Comment options

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