Skip to content

Commit 27a6cd8

Browse files
Add comments about mypy limitation regarding TypeVar constraints
1 parent d6ce3ab commit 27a6cd8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

stdlib/builtins.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,8 @@ class memoryview(Sized, Sequence[int]):
725725
@final
726726
class bool(int):
727727
def __new__(cls: type[Self], __o: object = ...) -> Self: ...
728+
# The following overloads could be represented more elegantly with a TypeVar("_B", bool, int),
729+
# however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880).
728730
@overload
729731
def __and__(self, __x: bool) -> bool: ...
730732
@overload

stdlib/re.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ if sys.version_info < (3, 7):
5151
# undocumented
5252
_pattern_type: type
5353

54+
# Type-wise these overloads are unnecessary, they could also be modeled using
55+
# unions in the parameter types. However mypy has a bug regarding TypeVar
56+
# constraints (https://github.com/python/mypy/issues/11880),
57+
# which limits us here because AnyStr is a constrained TypeVar.
58+
5459
@overload
5560
def compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]: ...
5661
@overload

0 commit comments

Comments
 (0)