Skip to content

Commit 140bba3

Browse files
authored
Add comments when subclassing Any (#9732)
1 parent c437f5b commit 140bba3

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

stdlib/distutils/command/check.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ from ..cmd import Command
66
_Reporter: TypeAlias = Any # really docutils.utils.Reporter
77

88
# Only defined if docutils is installed.
9+
# Depends on a third-party stub. Since distutils is deprecated anyway,
10+
# it's easier to just suppress the "any subclassing" error.
911
class SilentReporter(_Reporter):
1012
messages: Any
1113
def __init__(

stdlib/unittest/mock.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class _CallList(list[_Call]):
101101
class Base:
102102
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
103103

104+
# We subclass with "Any" because mocks are explicitly designed to stand in for other types,
105+
# something that can't be expressed with our static type system.
104106
class NonCallableMock(Base, Any):
105107
def __new__(__cls, *args: Any, **kw: Any) -> Self: ...
106108
def __init__(

stubs/Pillow/PIL/ImageQt.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ from typing_extensions import Literal, TypeAlias
33

44
from .Image import Image
55

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

912
qt_versions: Any

stubs/mock/mock/mock.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class _CallList(list[_Call]):
8181
class Base:
8282
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
8383

84+
# We subclass with "Any" because mocks are explicitly designed to stand in for other types,
85+
# something that can't be expressed with our static type system.
8486
class NonCallableMock(Base, Any):
8587
def __new__(
8688
cls: type[Self],

tests/mypy_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ def run_mypy(
263263
# Stub completion is checked by pyright (--allow-*-defs)
264264
"--allow-untyped-defs",
265265
"--allow-incomplete-defs",
266-
"--allow-subclassing-any", # See #9491
266+
# See https://github.com/python/typeshed/pull/9491#issuecomment-1381574946
267+
# for discussion and reasoning to keep "--allow-subclassing-any"
268+
"--allow-subclassing-any",
267269
"--enable-error-code",
268270
"ignore-without-code",
269271
"--config-file",

0 commit comments

Comments
 (0)