Any plans to support attrs? #287
-
|
Currently the Today, this raises the following
@attrs.define()
class Data1:
s : str = "s"
n: int = 1
def do_something(inst: AttrsInstance) -> None:
pass
inst = Data1()
do_something(inst)Any plan to support attrs? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
|
Right now this behavior is expected in Pyright. Mypy has special casing for attrs classes. It understands that a class decorated with So the issue is not with your class definition. It is a type checker feature gap. At the moment, Pyright does not provide full parity with mypy’s attrs plugin behavior. There has been discussion about improving attrs support, but it requires explicit modeling of attrs semantics inside the type checker. Without that, protocols like If you need a working solution today, you have a few options: You can avoid using You can introduce a type variable bound to a base class if you control the hierarchy. Or you can use mypy for projects that depend heavily on attrs specific typing behavior. In short, this is not a problem with attrs itself, but a difference in how static analyzers implement support. Pyright would need explicit attrs awareness to behave like mypy here. |
Beta Was this translation helpful? Give feedback.
-
|
Hi Johann I have no current plans of supporting attrs, but I would probably look into it in two cases:
I'm aware that Mypy supports this and I have intentionally skipped the attrs related tests for now. Sorry if this doesn't help you, but it's just not a big priority. Is there an upside to using attrs vs. dataclasses or do you simply use it, because attrs has been around before dataclasses and it's hard to migrate a bigger code base? |
Beta Was this translation helpful? Give feedback.
Hi Johann
I have no current plans of supporting attrs, but I would probably look into it in two cases:
I'm aware that Mypy supports this and I have intentionally skipped the attrs related tests for now.
Sorry if this doesn't help you, but it's just not a big priority.
Is there an upside to using attrs vs. dataclasses or do you simply use it, because attrs has been around before dataclasses and it's hard to migrate a bigger code base?