Skip to content

Add comments about mypy limitation regarding TypeVar constraints #7350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions stdlib/re.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down