You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar treatment for dataclasses.replace would also be nice. (There was previously PR #14263 but that one only checked that the first argument to replace is a dataclass – which can also be done by just modifying the type stubs.)
Applying the same technique to attrs would be difficult unless all type checkers could be counted on to synthesise __attrs_attrs__ attributes for attrs classes in the same way that they can be counted on to synthesise __dataclass_fields__ attributes for classes decorated with @dataclass. Mypy has a custom plugin for attrs, meaning it can be counted on to synthesise this attribute. On the other hand, pyright has (reasonably) resisted adding any special-casing for any third-party libraries.
If attrs ships its own type annotations, then they could decide that e.g. you could only used them with mypy and a certain plugin being installed, but I agree we cannot make this decision for typeshed's annotations.
And for this case, the plugin can easily make this check, and I would have to in #14526 anyway.
To be clear, attrs does ship its own type annotations, and typeshed does not have stubs for attrs. If somebody did want to try a solution for attrs along the lines of my dataclasses PR to typeshed, they'd have to implement it in the annotations shipped by attrs, not in typeshed.
Activity
tmke8 commentedon Jan 27, 2023
Similar treatment for
dataclasses.replacewould also be nice. (There was previously PR #14263 but that one only checked that the first argument toreplaceis a dataclass – which can also be done by just modifying the type stubs.)ikonst commentedon Jan 27, 2023
By modifying the type annotations? I don't think dataclasses have any common base, do they? Or maybe through a protocol?
tmke8 commentedon Jan 27, 2023
Yes, @AlexWaygood suggested doing it with a protocol: python/typeshed#9362
AlexWaygood commentedon Jan 27, 2023
Applying the same technique to
attrswould be difficult unless all type checkers could be counted on to synthesise__attrs_attrs__attributes forattrsclasses in the same way that they can be counted on to synthesise__dataclass_fields__attributes for classes decorated with@dataclass. Mypy has a custom plugin forattrs, meaning it can be counted on to synthesise this attribute. On the other hand, pyright has (reasonably) resisted adding any special-casing for any third-party libraries.ikonst commentedon Jan 27, 2023
If attrs ships its own type annotations, then they could decide that e.g. you could only used them with mypy and a certain plugin being installed, but I agree we cannot make this decision for typeshed's annotations.
And for this case, the plugin can easily make this check, and I would have to in #14526 anyway.
AlexWaygood commentedon Jan 27, 2023
To be clear,
attrsdoes ship its own type annotations, and typeshed does not have stubs forattrs. If somebody did want to try a solution forattrsalong the lines of mydataclassesPR to typeshed, they'd have to implement it in the annotations shipped byattrs, not in typeshed.Add signature for attr.evolve (#14526)