[QUESTION] dependencies inherited from typing.Generic
See original GitHub issueHow can I avoid ‘args’ and ‘kwargs’ as a required query parameters if I use typing.Generic?
I have got next generic base class
from typing import Generic, Type, TypeVar
ModelType = TypeVar("ModelType", bound=BaseModel)
CreateSchemaType = TypeVar("CreateSchemaType", bound=BaseModel)
UpdateSchemaType = TypeVar("UpdateSchemaType", bound=BaseModel)
class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]):
def __init__(self, db: Database, table: Table, model: Type[ModelType]):
self.db = db
self.model = model
self.table = table
And successor class which used as a dependency
class UserService(CRUDBase[User, UserCreate, UserUpdate]):
def __init__(self, db: Database = Depends(get_db)):
super().__init__(db, UserTable, User)
Since typing.Generic has overwritten __new__
method, so FastAPI makes args
and kwargs
as a required query attributes.
I have only one solution with a factory function, have you another solution?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Dependency Injection with inheritance and Generics in .NET ...
Here's the way to register generic dependencies. public static void Main() { var services = new ServiceCollection(); services.
Read more >Inherit a class that inherits a generic class to make it easier to ...
I'm creating a simple Dependency Injection library for Unity (no constructors available) and I want to use a generic class that implements a ......
Read more >Crossing the Generics Divide - Jimmy Bogard
Our problem here is we need to "know" the service type at compile time in order to pass that value through to the...
Read more >Issue 38459: typing: Classes that inherit `Generic[...]` indirectly ...
typing : Classes that inherit `Generic[...]` indirectly aren't considered generic. Type: behavior, Stage: resolved. Components: Library (Lib) ...
Read more >Java Generics Example Tutorial - Generic Method, Class ...
Notice that at the time of list creation, we have specified that the type of elements in the list will be String. So...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got it working somehow with this decorator.