Closed adampauls closed 2 months ago
Pyright is working as intended here, so I don't consider this a bug.
The fields
function is defined as follows in typeshed:
def fields(class_or_instance: DataclassInstance | type[DataclassInstance]) -> tuple[Field[Any], ...]: ...
Not surprisingly, mypy's behavior is the same here.
I'm sorry, I don't understand your response. Indeed the type of fields is a tuple of fields. My issue is that the type of field.type
does not match the typeshed declaration. I suppose that now that Any
is in the type, there's no point in having type[T]
in the union (nor str
for that matter), but it's still jarring that pyright's type does not match the typeshed declaration.
Ah, I see what you mean now. You expected the resulting type to be type[Any] | str | Any
.
Here's a code sample that demonstrates this more clearly.
from dataclasses import Field
from typing import Any
def func(x: Field[Any]):
reveal_type(x.type) # should be type[Any] | str | Any
I agree this is a bug, and it will be fixed in the next release.
This is addressed in pyright 1.1.372.
Describe the bug Field.type on in
dataclasses
was recently changed to have typeType[_T] | str | Any
. However, pyright seems to think the type isAny | str
.Code or Screenshots