Closed Pacheco95 closed 2 years ago
Not the developer here, but I'm pretty sure that the current type annotations are actually correct. data_class
is not an object of type T
but the type itself. Consider the examples at https://docs.python.org/3/library/typing.html#typing.Type. Basically,
a = 3 # Has type 'int'
b = int # Has type 'Type[int]'
c = type(a) # Also has type 'Type[int]'
If the dataclass we want to instantiate using from_dict
is User
then we would call the function like this: from_dict(data_class=User, data=data)
for some data
and expect that it returns an instance of User
. So the parameter data_class
has type Type[User]
and the return type is User
.
Could you maybe provide the issues that Intellisense has with your code and the original function definition?
Hi @Pacheco95 - thank you for your issue.
I agree with @BurningKarl that it should be Type[T]
as it is now.
In
v1.6.0
from_dict
is defined asIntellissense is not working. I think the correct way to define generic functions is like
I just edited the source code directly from PyCharm and everything works well
See documentation https://docs.python.org/3/library/typing.html#typing.TypeVar