From 8f82785f84092e92ecc6e423fcff5b9abfcc168e Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Wed, 6 Apr 2022 11:19:02 +0200 Subject: [PATCH 1/2] Add missing cmp_using to stub files Signed-off-by: Hynek Schlawack --- docs/comparison.rst | 2 +- src/attr/__init__.pyi | 2 +- src/attr/_cmp.pyi | 4 ++-- src/attrs/__init__.pyi | 1 + tests/typing_example.py | 2 ++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/comparison.rst b/docs/comparison.rst index 760124ca3..0a2e432f3 100644 --- a/docs/comparison.rst +++ b/docs/comparison.rst @@ -50,7 +50,7 @@ It is then used as a key function like you may know from `sorted`: This is especially useful when you have fields with objects that have atypical comparison properties. Common examples of such objects are `NumPy arrays `_. -To save you unnecessary boilerplate, ``attrs`` comes with the `attr.cmp_using` helper to create such functions. +To save you unnecessary boilerplate, ``attrs`` comes with the `attrs.cmp_using` helper to create such functions. For NumPy arrays it would look like this:: import numpy diff --git a/src/attr/__init__.pyi b/src/attr/__init__.pyi index c0a212650..6e4707824 100644 --- a/src/attr/__init__.pyi +++ b/src/attr/__init__.pyi @@ -23,6 +23,7 @@ from . import filters as filters from . import setters as setters from . import validators as validators from ._version_info import VersionInfo +from ._cmp import cmp_using as cmp_using __version__: str __version_info__: VersionInfo @@ -51,7 +52,6 @@ _OnSetAttrArgType = Union[ _FieldTransformer = Callable[ [type, List[Attribute[Any]]], List[Attribute[Any]] ] -_CompareWithType = Callable[[Any, Any], bool] # FIXME: in reality, if multiple validators are passed they must be in a list # or tuple, but those are invariant and so would prevent subtypes of # _ValidatorType from working when passed in a list or tuple. diff --git a/src/attr/_cmp.pyi b/src/attr/_cmp.pyi index e71aaff7a..35437eff6 100644 --- a/src/attr/_cmp.pyi +++ b/src/attr/_cmp.pyi @@ -1,6 +1,6 @@ -from typing import Type +from typing import Any, Callable, Optional, Type -from . import _CompareWithType +_CompareWithType = Callable[[Any, Any], bool] def cmp_using( eq: Optional[_CompareWithType], diff --git a/src/attrs/__init__.pyi b/src/attrs/__init__.pyi index f99070891..fc44de46a 100644 --- a/src/attrs/__init__.pyi +++ b/src/attrs/__init__.pyi @@ -23,6 +23,7 @@ from attr import __version_info__ as __version_info__ from attr import _FilterType from attr import assoc as assoc from attr import Attribute as Attribute +from attr import cmp_using as cmp_using from attr import converters as converters from attr import define as define from attr import evolve as evolve diff --git a/tests/typing_example.py b/tests/typing_example.py index bb05af8f9..1c6691f75 100644 --- a/tests/typing_example.py +++ b/tests/typing_example.py @@ -403,6 +403,7 @@ def accessing_from_attr() -> None: attr.filters.include attr.setters.frozen attr.validators.and_ + attr.cmp_using def accessing_from_attrs() -> None: @@ -414,3 +415,4 @@ def accessing_from_attrs() -> None: attrs.filters.include attrs.setters.frozen attrs.validators.and_ + attrs.cmp_using From ca032eb65fb843e9bce4908a7523afaa07d1ab20 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Thu, 7 Apr 2022 07:12:07 +0200 Subject: [PATCH 2/2] Add newsfragment --- changelog.d/949.change.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/949.change.rst diff --git a/changelog.d/949.change.rst b/changelog.d/949.change.rst new file mode 100644 index 000000000..6e12e5355 --- /dev/null +++ b/changelog.d/949.change.rst @@ -0,0 +1 @@ +Added missing stub for ``attr(s).cmp_using()``.