Skip to content

Commit

Permalink
Add missing cmp_using to stub files (#949)
Browse files Browse the repository at this point in the history
* Add missing cmp_using to stub files

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* Add newsfragment
  • Loading branch information
hynek committed Apr 7, 2022
1 parent 0f08b84 commit 738ee63
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/949.change.rst
@@ -0,0 +1 @@
Added missing stub for ``attr(s).cmp_using()``.
2 changes: 1 addition & 1 deletion docs/comparison.rst
Expand Up @@ -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 <https://github.com/python-attrs/attrs/issues/435>`_.

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
Expand Down
2 changes: 1 addition & 1 deletion src/attr/__init__.pyi
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions 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],
Expand Down
1 change: 1 addition & 0 deletions src/attrs/__init__.pyi
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/typing_example.py
Expand Up @@ -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:
Expand All @@ -414,3 +415,4 @@ def accessing_from_attrs() -> None:
attrs.filters.include
attrs.setters.frozen
attrs.validators.and_
attrs.cmp_using

0 comments on commit 738ee63

Please sign in to comment.