PEP 483: Define AnyStr before mentioning it (#2682)

This commit is contained in:
Murtagy 2022-06-28 18:35:25 +03:00 committed by GitHub
parent 41e31d5d6a
commit dda79ea1c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -441,9 +441,9 @@ replaced by the most-derived base class among ``t1``, etc. Examples:
- Function type annotation with a constrained type variable::
S = TypeVar('S', str, bytes)
AnyStr = TypeVar('AnyStr', str, bytes)
def longest(first: S, second: S) -> S:
def longest(first: AnyStr, second: AnyStr) -> AnyStr:
return first if len(first) >= len(second) else second
result = longest('a', 'abc') # The inferred type for result is str