Add comments about mypy limitation regarding TypeVar constraints (#7350)

This commit is contained in:
Martin Fischer
2022-02-22 12:29:39 +01:00
committed by GitHub
parent d6ce3abd68
commit 51a3cf072c
2 changed files with 7 additions and 0 deletions

View File

@@ -725,6 +725,8 @@ class memoryview(Sized, Sequence[int]):
@final
class bool(int):
def __new__(cls: type[Self], __o: object = ...) -> Self: ...
# The following overloads could be represented more elegantly with a TypeVar("_B", bool, int),
# however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880).
@overload
def __and__(self, __x: bool) -> bool: ...
@overload

View File

@@ -51,6 +51,11 @@ if sys.version_info < (3, 7):
# undocumented
_pattern_type: type
# Type-wise these overloads are unnecessary, they could also be modeled using
# unions in the parameter types. However mypy has a bug regarding TypeVar
# constraints (https://github.com/python/mypy/issues/11880),
# which limits us here because AnyStr is a constrained TypeVar.
@overload
def compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]: ...
@overload