From c2712fd102ddfb7df6df333f421c3b21c18e4b37 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 29 Jan 2021 11:09:02 +0100 Subject: [PATCH] Add forgotten Attribute.evolve to stub Fixes #752 --- changelog.d/752.change.rst | 1 + src/attr/__init__.pyi | 2 ++ tests/typing_example.py | 4 ++++ 3 files changed, 7 insertions(+) create mode 100644 changelog.d/752.change.rst diff --git a/changelog.d/752.change.rst b/changelog.d/752.change.rst new file mode 100644 index 00000000..6e16f32a --- /dev/null +++ b/changelog.d/752.change.rst @@ -0,0 +1 @@ +Added forgotten ``attr.Attribute.evolve()`` to type stubs. diff --git a/src/attr/__init__.pyi b/src/attr/__init__.pyi index 12af0037..eb301b43 100644 --- a/src/attr/__init__.pyi +++ b/src/attr/__init__.pyi @@ -83,6 +83,8 @@ class Attribute(Generic[_T]): kw_only: bool on_setattr: _OnSetAttrType + def evolve(self, **changes: Any) -> "Attribute": ... + # NOTE: We had several choices for the annotation to use for type arg: # 1) Type[_T] # - Pros: Handles simple cases correctly diff --git a/tests/typing_example.py b/tests/typing_example.py index 5ecf27bb..db05dec3 100644 --- a/tests/typing_example.py +++ b/tests/typing_example.py @@ -242,6 +242,10 @@ class NGFrozen: ngf = NGFrozen(1) +attr.fields(NGFrozen).x.evolve(eq=False) +a = attr.fields(NGFrozen).x +a.evolve(repr=False) + @attr.s(collect_by_mro=True) class MRO: