Skip to content

disallow subclassing any #9491

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
000eb44
Explain why we sublass ImageQt with Any
Avasam Jan 5, 2023
679b276
disallow subclassing any
Avasam Jan 11, 2023
d7fd165
Add comment explaining NonCallableMock Any subclassing
Avasam Jan 11, 2023
85f7361
reword
Avasam Jan 11, 2023
b93062d
Merge branch 'main' into disallow-subclassing-any
AlexWaygood Jan 11, 2023
eb78b23
Merge branch 'main' into disallow-subclassing-any
AlexWaygood Jan 11, 2023
2016689
Merge branch 'mock-subclassing-any' of https://github.com/Avasam/type…
Avasam Jan 11, 2023
9005a18
Update comment
Avasam Jan 11, 2023
8dc1b4c
Merge branch 'disallow-subclassing-any' of https://github.com/Avasam/…
Avasam Jan 11, 2023
ea09370
Merge branch 'ImageQt-any-subclassing' of https://github.com/Avasam/t…
Avasam Jan 12, 2023
c8fe1cf
Merge branch 'main' of https://github.com/python/typeshed into disall…
Avasam Jan 12, 2023
826532f
SQLAlchemy's _DeclarativeBase(Any)
Avasam Jan 12, 2023
e5f0d3d
Suppress any subclassing error in distutils
Avasam Jan 12, 2023
b2ffbe8
Merge branch 'main' into disallow-subclassing-any
AlexWaygood Jan 13, 2023
423990a
Merge branch 'main' into disallow-subclassing-any
AlexWaygood Jan 14, 2023
36845c1
Merge branch 'main' into disallow-subclassing-any
Avasam Feb 1, 2023
092e794
Merge branch 'main' of https://github.com/python/typeshed into disall…
Avasam Feb 8, 2023
12538ab
Fix leftover underscore from bad merge
Avasam Feb 8, 2023
c6d0037
other way around
Avasam Feb 8, 2023
7fa814b
Merge branch 'main' of https://github.com/python/typeshed into disall…
Avasam Feb 14, 2023
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
4 changes: 3 additions & 1 deletion stdlib/distutils/command/check.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ from ..cmd import Command
_Reporter: TypeAlias = Any # really docutils.utils.Reporter

# Only defined if docutils is installed.
class SilentReporter(_Reporter):
# Depends on a third-party stub. Since distutils is deprecated anyway,
# it's easier to just suppress the "any subclassing" error.
class SilentReporter(_Reporter): # type: ignore[misc]
messages: Any
def __init__(
self,
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
7 changes: 5 additions & 2 deletions 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 All @@ -15,7 +18,7 @@ def fromqimage(im: ImageQt | _QImage) -> Image: ...
def fromqpixmap(im: ImageQt | _QImage) -> Image: ...
def align8to32(bytes: bytes, width: int, mode: Literal["1", "L", "P"]) -> bytes: ...

class ImageQt(_QImage):
class ImageQt(_QImage): # type: ignore[misc]
def __init__(self, im: Image) -> None: ...

def toqimage(im: Image) -> ImageQt: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _DeclT = TypeVar("_DeclT", bound=type[_DeclarativeBase])

# Dynamic class as created by registry.generate_base() via DeclarativeMeta
# or another metaclass. This class does not exist at runtime.
class _DeclarativeBase(Any): # super classes are dynamic
class _DeclarativeBase(Any): # type: ignore[misc] # super classes are dynamic
registry: ClassVar[registry]
metadata: ClassVar[MetaData]
__abstract__: ClassVar[bool]
Expand Down
4 changes: 3 additions & 1 deletion stubs/mock/mock/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class _CallList(list[_Call]):
class Base:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class NonCallableMock(Base, Any):
# 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): # type: ignore[misc]
def __new__(
cls: type[Self],
spec: list[str] | object | type[object] | None = ...,
Expand Down
1 change: 0 additions & 1 deletion tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ def run_mypy(
# Stub completion is checked by pyright (--allow-*-defs)
"--allow-untyped-defs",
"--allow-incomplete-defs",
"--allow-subclassing-any", # See #9491
"--enable-error-code",
"ignore-without-code",
"--config-file",
Expand Down