Skip to content

Add comments when subclassing Any #9732

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 14, 2023
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/distutils/command/check.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ from ..cmd import Command
_Reporter: TypeAlias = Any # really docutils.utils.Reporter

# Only defined if docutils is installed.
# Depends on a third-party stub. Since distutils is deprecated anyway,
# it's easier to just suppress the "any subclassing" error.
class SilentReporter(_Reporter):
messages: Any
def __init__(
Expand Down
2 changes: 2 additions & 0 deletions stdlib/unittest/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class _CallList(list[_Call]):
class Base:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

# We subclass with "Any" because mocks are explicitly designed to stand in for other types,
# something that can't be expressed with our static type system.
class NonCallableMock(Base, Any):
def __new__(__cls, *args: Any, **kw: Any) -> Self: ...
def __init__(
Expand Down
5 changes: 4 additions & 1 deletion stubs/Pillow/PIL/ImageQt.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ from typing_extensions import Literal, TypeAlias

from .Image import Image

_QImage: TypeAlias = Any # imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui
# imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui
# These are way too complex, with 4 different possible sources (2 deprecated)
# And we don't want to force the user to install PyQt or Pyside when they may not even use it.
_QImage: TypeAlias = Any
_QPixmap: TypeAlias = Any

qt_versions: Any
Expand Down
2 changes: 2 additions & 0 deletions stubs/mock/mock/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class _CallList(list[_Call]):
class Base:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

# We subclass with "Any" because mocks are explicitly designed to stand in for other types,
# something that can't be expressed with our static type system.
class NonCallableMock(Base, Any):
def __new__(
cls: type[Self],
Expand Down
4 changes: 3 additions & 1 deletion tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ def run_mypy(
# Stub completion is checked by pyright (--allow-*-defs)
"--allow-untyped-defs",
"--allow-incomplete-defs",
"--allow-subclassing-any", # See #9491
# See https://github.com/python/typeshed/pull/9491#issuecomment-1381574946
# for discussion and reasoning to keep "--allow-subclassing-any"
"--allow-subclassing-any",
"--enable-error-code",
"ignore-without-code",
"--config-file",
Expand Down