PEP 483: Define AnyStr before mentioning it (#2682)
This commit is contained in:
parent
41e31d5d6a
commit
dda79ea1c3
|
@ -441,9 +441,9 @@ replaced by the most-derived base class among ``t1``, etc. Examples:
|
||||||
|
|
||||||
- Function type annotation with a constrained type variable::
|
- 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
|
return first if len(first) >= len(second) else second
|
||||||
|
|
||||||
result = longest('a', 'abc') # The inferred type for result is str
|
result = longest('a', 'abc') # The inferred type for result is str
|
||||||
|
|
Loading…
Reference in New Issue