-
I have this piece of code, which type checks fine: import datetime as dt
from enum import Enum, auto
from typing import Any, Self
from attrs import define, field
@define
class Foo:
one: dt.datetime = field(converter=[dt.datetime.fromisoformat])
@classmethod
def from_json(cls, data: dict[str, Any]) -> Self:
return cls(**data)
@define
class Bar:
class Tag(Enum):
THREE = auto()
two: Foo = field(converter=Foo.from_json)
def unused() -> set[Bar.Tag]:
return set() If I add from __future__ import annotations
import datetime as dt
from enum import Enum, auto
from typing import Any, Self
from attrs import define, field
def unused() -> set[Bar.Tag]:
return set()
@define
class Foo:
one: dt.datetime = field(converter=[dt.datetime.fromisoformat])
@classmethod
def from_json(cls, data: dict[str, Any]) -> Self:
return cls(**data)
@define
class Bar:
class Tag(Enum):
THREE = auto()
two: Foo = field(converter=Foo.from_json) pyright reports these errors:
Which doesn't make sense to me -- the arguments to This is my environment:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm not able to repro the problem as reported. For me, pyright 1.1.390 reports the same error for both pieces of code above. Can you please confirm that you are able to repro a difference between the two? Order dependencies like this typically hint at a circular dependency between types in your code. In such cases, pyright needs to break the cycle by choosing an arbitrary point in the cycle to begin evaluation. Depending on where it starts the evaluation, this can lead to different errors because of partially-evaluated type information. However, I don't see any circularity in your code example. Perhaps you over-simplified the code when you were creating the sample? |
Beta Was this translation helpful? Give feedback.
OK, thanks. I had a slightly older version of attrs installed. With the latest version, I'm able to repro this. Apologies for my initial oversight.
I've checked in a fix, and it will be included in the next release of pyright.