Skip to content

Commit

Permalink
Fix IsDigit -> IsDigits (#63)
Browse files Browse the repository at this point in the history
* Fix IsDigit -> IsDigits

* fix IsDigit typo, leave alias

---------

Co-authored-by: Zac Hatfield-Dodds <[email protected]>
  • Loading branch information
toriningen and Zac-HD authored Mar 3, 2024
1 parent 59a50d1 commit 89e3d2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions annotated_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class Predicate(BaseMetadata):
We provide a few predefined predicates for common string constraints:
``IsLower = Predicate(str.islower)``, ``IsUpper = Predicate(str.isupper)``, and
``IsDigit = Predicate(str.isdigit)``. Users are encouraged to use methods which
``IsDigits = Predicate(str.isdigit)``. Users are encouraged to use methods which
can be given special handling, and avoid indirection like ``lambda s: s.lower()``.
Some libraries might have special logic to handle certain predicates, e.g. by
Expand Down Expand Up @@ -354,7 +354,8 @@ def __call__(self, __v: Any) -> bool:
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
""" # noqa: E501
IsDigits = Annotated[_StrType, Predicate(str.isdigit)]
IsDigit = Annotated[_StrType, Predicate(str.isdigit)]
IsDigits = IsDigit # type: ignore # plural for backwards compatibility, see #63
"""
Return True if the string is a digit string, False otherwise.
Expand Down
2 changes: 1 addition & 1 deletion annotated_types/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def cases() -> Iterable[Case]:

yield Case(at.LowerCase[str], ['abc', 'foobar'], ['', 'A', 'Boom'])
yield Case(at.UpperCase[str], ['ABC', 'DEFO'], ['', 'a', 'abc', 'AbC'])
yield Case(at.IsDigits[str], ['123'], ['', 'ab', 'a1b2'])
yield Case(at.IsDigit[str], ['123'], ['', 'ab', 'a1b2'])
yield Case(at.IsAscii[str], ['123', 'foo bar'], ['£100', '😊', 'whatever 👀'])

yield Case(Annotated[int, at.Predicate(lambda x: x % 2 == 0)], [0, 2, 4], [1, 3, 5])
Expand Down

0 comments on commit 89e3d2e

Please sign in to comment.