Never explicitly inherit from object in Python 3-only stubs (#6777)

This commit is contained in:
Alex Waygood
2022-01-02 06:24:48 +00:00
committed by GitHub
parent d43cd997a4
commit 505ea72641
35 changed files with 79 additions and 67 deletions

View File

@@ -9,7 +9,7 @@ def get_ident() -> int: ...
def allocate_lock() -> LockType: ...
def stack_size(size: int | None = ...) -> int: ...
class LockType(object):
class LockType:
locked_status: bool
def __init__(self) -> None: ...
def acquire(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...

View File

@@ -28,7 +28,7 @@ TIMEOUT_MAX: float
class ThreadError(Exception): ...
class local(object):
class local:
def __getattribute__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...

View File

@@ -1,7 +1,7 @@
# Actually Tuple[(int,) * 625]
_State = tuple[int, ...]
class Random(object):
class Random:
def __init__(self, seed: object = ...) -> None: ...
def seed(self, __n: object = ...) -> None: ...
def getstate(self) -> _State: ...

View File

@@ -138,7 +138,7 @@ class classmethod(Generic[_R]): # Special, only valid as a decorator.
__qualname__: str
__wrapped__: Callable[..., _R]
class type(object):
class type:
__base__: type
__bases__: tuple[type, ...]
__basicsize__: int
@@ -173,7 +173,7 @@ class type(object):
def __or__(self, __t: Any) -> types.UnionType: ...
def __ror__(self, __t: Any) -> types.UnionType: ...
class super(object):
class super:
@overload
def __init__(self, __t: Any, __obj: Any) -> None: ...
@overload
@@ -729,7 +729,7 @@ class bool(int):
def __getnewargs__(self) -> tuple[int]: ...
@final
class slice(object):
class slice:
start: Any
step: Any
stop: Any
@@ -951,7 +951,7 @@ class range(Sequence[int]):
def __repr__(self) -> str: ...
def __reversed__(self) -> Iterator[int]: ...
class property(object):
class property:
fget: Callable[[Any], Any] | None
fset: Callable[[Any, Any], None] | None
fdel: Callable[[Any], None] | None
@@ -1500,7 +1500,7 @@ class ellipsis: ...
Ellipsis: ellipsis
class BaseException(object):
class BaseException:
args: tuple[Any, ...]
__cause__: BaseException | None
__context__: BaseException | None

View File

@@ -128,13 +128,13 @@ class BZ2File(BaseStream, IO[bytes]):
def writelines(self, seq: Iterable[ReadableBuffer]) -> None: ...
@final
class BZ2Compressor(object):
class BZ2Compressor:
def __init__(self, compresslevel: int = ...) -> None: ...
def compress(self, __data: bytes) -> bytes: ...
def flush(self) -> bytes: ...
@final
class BZ2Decompressor(object):
class BZ2Decompressor:
def decompress(self, data: bytes, max_length: int = ...) -> bytes: ...
@property
def eof(self) -> bool: ...

View File

@@ -57,7 +57,7 @@ class MiniFieldStorage:
_list = list
class FieldStorage(object):
class FieldStorage:
FieldStorageClass: _type | None
keep_blank_values: int
strict_parsing: int

View File

@@ -100,7 +100,7 @@ class DictWriter(Generic[_T]):
def writerow(self, rowdict: Mapping[_T, Any]) -> Any: ...
def writerows(self, rowdicts: Iterable[Mapping[_T, Any]]) -> None: ...
class Sniffer(object):
class Sniffer:
preferred: list[str]
def __init__(self) -> None: ...
def sniff(self, sample: str, delimiters: str | None = ...) -> Type[Dialect]: ...

View File

@@ -28,7 +28,7 @@ RTLD_GLOBAL: int
RTLD_LOCAL: int
DEFAULT_MODE: int
class CDLL(object):
class CDLL:
_func_flags_: ClassVar[int]
_func_restype_: ClassVar[_CData]
_name: str

View File

@@ -49,7 +49,7 @@ def setcontext(__context: Context) -> None: ...
def getcontext() -> Context: ...
def localcontext(ctx: Context | None = ...) -> _ContextManager: ...
class Decimal(object):
class Decimal:
def __new__(cls: Type[_DecimalT], value: _DecimalNew = ..., context: Context | None = ...) -> _DecimalT: ...
@classmethod
def from_float(cls, __f: float) -> Decimal: ...
@@ -151,7 +151,7 @@ class Decimal(object):
def __deepcopy__(self, __memo: Any) -> Decimal: ...
def __format__(self, __specifier: str, __context: Context | None = ...) -> str: ...
class _ContextManager(object):
class _ContextManager:
new_context: Context
saved_context: Context
def __init__(self, new_context: Context) -> None: ...
@@ -160,7 +160,7 @@ class _ContextManager(object):
_TrapType = Type[DecimalException]
class Context(object):
class Context:
prec: int
rounding: str
Emin: int

View File

@@ -70,7 +70,7 @@ def ndiff(
a: Sequence[str], b: Sequence[str], linejunk: _JunkCallback | None = ..., charjunk: _JunkCallback | None = ...
) -> Iterator[str]: ...
class HtmlDiff(object):
class HtmlDiff:
def __init__(
self,
tabsize: int = ...,

View File

@@ -2,7 +2,7 @@ import sys
from _typeshed import ReadableBuffer, Self
from typing import AbstractSet
class _Hash(object):
class _Hash:
@property
def digest_size(self) -> int: ...
@property
@@ -49,7 +49,7 @@ def pbkdf2_hmac(
hash_name: str, password: ReadableBuffer, salt: ReadableBuffer, iterations: int, dklen: int | None = ...
) -> bytes: ...
class _VarLenHash(object):
class _VarLenHash:
digest_size: int
block_size: int
name: str

View File

@@ -27,14 +27,14 @@ def currentframe() -> FrameType: ...
_levelToName: dict[int, str]
_nameToLevel: dict[str, int]
class Filterer(object):
class Filterer:
filters: list[Filter]
def __init__(self) -> None: ...
def addFilter(self, filter: _FilterType) -> None: ...
def removeFilter(self, filter: _FilterType) -> None: ...
def filter(self, record: LogRecord) -> bool: ...
class Manager(object): # undocumented
class Manager: # undocumented
root: RootLogger
disable: int
emittedNoHandlerWarning: bool
@@ -749,7 +749,7 @@ class RootLogger(Logger):
root: RootLogger
class PercentStyle(object): # undocumented
class PercentStyle: # undocumented
default_format: str
asctime_format: str
asctime_search: str

View File

@@ -41,7 +41,7 @@ PRESET_EXTREME: int
# from _lzma.c
@final
class LZMADecompressor(object):
class LZMADecompressor:
def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ...
def decompress(self, data: bytes, max_length: int = ...) -> bytes: ...
@property
@@ -55,7 +55,7 @@ class LZMADecompressor(object):
# from _lzma.c
@final
class LZMACompressor(object):
class LZMACompressor:
def __init__(
self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
) -> None: ...

View File

@@ -19,7 +19,7 @@ class BufferTooShort(ProcessError): ...
class TimeoutError(ProcessError): ...
class AuthenticationError(ProcessError): ...
class BaseContext(object):
class BaseContext:
Process: Type[BaseProcess]
ProcessError: Type[Exception]
BufferTooShort: Type[Exception]

View File

@@ -7,7 +7,7 @@ families: list[None]
_Address = Union[str, tuple[str, int]]
class Connection(object):
class Connection:
_in: Any
_out: Any
recv: Any
@@ -22,7 +22,7 @@ class Connection(object):
def close(self) -> None: ...
def poll(self, timeout: float = ...) -> bool: ...
class Listener(object):
class Listener:
_backlog_queue: Queue[Any] | None
@property
def address(self) -> Queue[Any] | None: ...

View File

@@ -27,7 +27,7 @@ class Namespace:
_Namespace = Namespace
class Token(object):
class Token:
typeid: str | bytes | None
address: tuple[str | bytes, int]
id: str | bytes | int | None
@@ -36,7 +36,7 @@ class Token(object):
def __getstate__(self) -> tuple[str | bytes | None, tuple[str | bytes, int], str | bytes | int | None]: ...
def __setstate__(self, state: tuple[str | bytes | None, tuple[str | bytes, int], str | bytes | int | None]) -> None: ...
class BaseProxy(object):
class BaseProxy:
_address_to_local: dict[Any, Any]
_mutex: Any
def __init__(

View File

@@ -9,7 +9,7 @@ TAKEN_FROM_ARGUMENT4: int
TAKEN_FROM_ARGUMENT4U: int
TAKEN_FROM_ARGUMENT8U: int
class ArgumentDescriptor(object):
class ArgumentDescriptor:
name: str
n: int
reader: _Reader
@@ -106,7 +106,7 @@ def read_long4(f: IO[bytes]) -> int: ...
long4: ArgumentDescriptor
class StackObject(object):
class StackObject:
name: str
obtype: Type[Any] | tuple[Type[Any], ...]
doc: str
@@ -131,7 +131,7 @@ anyobject: StackObject
markobject: StackObject
stackslice: StackObject
class OpcodeInfo(object):
class OpcodeInfo:
name: str
code: str
arg: ArgumentDescriptor | None

View File

@@ -23,7 +23,7 @@ XML_PARAM_ENTITY_PARSING_ALWAYS: int
_Model = tuple[int, int, Optional[str], tuple[Any, ...]]
@final
class XMLParserType(object):
class XMLParserType:
def Parse(self, __data: str | bytes, __isfinal: bool = ...) -> int: ...
def ParseFile(self, __file: SupportsRead[bytes]) -> int: ...
def SetBase(self, __base: str) -> None: ...

View File

@@ -33,7 +33,7 @@ error = OSError
if sys.platform != "linux" and sys.platform != "win32":
# BSD only
class kevent(object):
class kevent:
data: Any
fflags: int
filter: int
@@ -50,7 +50,7 @@ if sys.platform != "linux" and sys.platform != "win32":
udata: Any = ...,
) -> None: ...
# BSD only
class kqueue(object):
class kqueue:
closed: bool
def __init__(self) -> None: ...
def close(self) -> None: ...
@@ -100,7 +100,7 @@ if sys.platform != "linux" and sys.platform != "win32":
KQ_NOTE_WRITE: int
if sys.platform == "linux":
class epoll(object):
class epoll:
def __init__(self, sizehint: int = ..., flags: int = ...) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(

View File

@@ -117,7 +117,7 @@ def register_adapter(__type: Type[_T], __caster: Callable[[_T], int | float | st
def register_converter(__name: str, __converter: Callable[[bytes], Any]) -> None: ...
if sys.version_info < (3, 8):
class Cache(object):
class Cache:
def __init__(self, *args, **kwargs) -> None: ...
def display(self, *args, **kwargs) -> None: ...
def get(self, *args, **kwargs) -> None: ...
@@ -126,7 +126,7 @@ class _AggregateProtocol(Protocol):
def step(self, value: int) -> None: ...
def finalize(self) -> int: ...
class Connection(object):
class Connection:
DataError: Any
DatabaseError: Any
Error: Any
@@ -221,12 +221,12 @@ class OperationalError(DatabaseError): ...
OptimizedUnicode = str
class PrepareProtocol(object):
class PrepareProtocol:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
class ProgrammingError(DatabaseError): ...
class Row(object):
class Row:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def keys(self): ...
def __eq__(self, other): ...
@@ -241,7 +241,7 @@ class Row(object):
def __ne__(self, other): ...
if sys.version_info < (3, 8):
class Statement(object):
class Statement:
def __init__(self, *args, **kwargs): ...
class Warning(Exception): ...

View File

@@ -3,7 +3,7 @@ from typing import Any, Sequence
def symtable(code: str, filename: str, compile_type: str) -> SymbolTable: ...
class SymbolTable(object):
class SymbolTable:
def __init__(self, raw_table: Any, filename: str) -> None: ...
def get_type(self) -> str: ...
def get_id(self) -> int: ...
@@ -29,7 +29,7 @@ class Function(SymbolTable):
class Class(SymbolTable):
def get_methods(self) -> tuple[str, ...]: ...
class Symbol(object):
class Symbol:
if sys.version_info >= (3, 8):
def __init__(
self, name: str, flags: int, namespaces: Sequence[SymbolTable] | None = ..., *, module_scope: bool = ...
@@ -51,7 +51,7 @@ class Symbol(object):
def get_namespaces(self) -> Sequence[SymbolTable]: ...
def get_namespace(self) -> SymbolTable: ...
class SymbolTableFactory(object):
class SymbolTableFactory:
def __init__(self) -> None: ...
def new(self, table: Any, filename: str) -> SymbolTable: ...
def __call__(self, table: Any, filename: str) -> SymbolTable: ...

View File

@@ -34,7 +34,7 @@ TIMEOUT_MAX: float
class ThreadError(Exception): ...
class local(object):
class local:
def __getattribute__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...

View File

@@ -20,7 +20,7 @@ Vec2D = tuple[float, float]
class ScrolledCanvas(Frame): ...
class TurtleScreenBase(object):
class TurtleScreenBase:
cv: Canvas
canvwidth: int
canvheight: int
@@ -36,7 +36,7 @@ class TurtleScreenBase(object):
class Terminator(Exception): ...
class TurtleGraphicsError(Exception): ...
class Shape(object):
class Shape:
def __init__(self, type_: str, data: _PolygonCoords | PhotoImage | None = ...) -> None: ...
def addcomponent(self, poly: _PolygonCoords, fill: _Color, outline: _Color | None = ...) -> None: ...
@@ -94,7 +94,7 @@ class TurtleScreen(TurtleScreenBase):
def onkeypress(self, fun: Callable[[], Any], key: str | None = ...) -> None: ...
onkeyrelease = onkey
class TNavigator(object):
class TNavigator:
START_ORIENTATION: dict[str, Vec2D]
DEFAULT_MODE: str
DEFAULT_ANGLEOFFSET: int
@@ -138,7 +138,7 @@ class TNavigator(object):
setposition = goto
seth = setheading
class TPen(object):
class TPen:
def __init__(self, resizemode: str = ...) -> None: ...
@overload
def resizemode(self, rmode: None = ...) -> str: ...

View File

@@ -24,7 +24,7 @@ def name(__chr: str, __default: _T = ...) -> str | _T: ...
def normalize(__form: str, __unistr: str) -> str: ...
def numeric(__chr: str, __default: _T = ...) -> float | _T: ...
class UCD(object):
class UCD:
# The methods below are constructed from the same array in C
# (unicodedata_functions) and hence identical to the methods above.
unidata_version: str

View File

@@ -17,7 +17,7 @@ class TextTestResult(unittest.result.TestResult):
def printErrors(self) -> None: ...
def printErrorList(self, flavour: str, errors: tuple[unittest.case.TestCase, str]) -> None: ...
class TextTestRunner(object):
class TextTestRunner:
resultclass: _ResultClassType
def __init__(
self,

View File

@@ -9,7 +9,7 @@ if sys.version_info >= (3, 7):
class ZipImportError(ImportError): ...
class zipimporter(object):
class zipimporter:
archive: str
prefix: str
def __init__(self, path: str | bytes | os.PathLike[Any]) -> None: ...

View File

@@ -3,7 +3,7 @@ from typing import Iterable
from dateutil.relativedelta import relativedelta
class DateTimeRange(object):
class DateTimeRange:
NOT_A_TIME_STR: str
start_time_format: str
end_time_format: str

View File

@@ -1,16 +1,16 @@
from collections.abc import Generator, Iterable
from typing import Any
class HTMLParser(object): # actually html5lib.HTMLParser
class HTMLParser: # actually html5lib.HTMLParser
def __getattr__(self, __name: str) -> Any: ... # incomplete
class Filter(object): # actually html5lib.filters.base.Filter
class Filter: # actually html5lib.filters.base.Filter
def __getattr__(self, __name: str) -> Any: ... # incomplete
class SanitizerFilter(object): # actually html5lib.filters.sanitizer.Filter
class SanitizerFilter: # actually html5lib.filters.sanitizer.Filter
def __getattr__(self, __name: str) -> Any: ... # incomplete
class HTMLSerializer(object): # actually html5lib.serializer.HTMLSerializer
class HTMLSerializer: # actually html5lib.serializer.HTMLSerializer
def __getattr__(self, __name: str) -> Any: ... # incomplete
class BleachHTMLParser(HTMLParser):

View File

@@ -21,7 +21,7 @@ def build_email_re(tlds: Iterable[str] = ...) -> Pattern[str]: ...
EMAIL_RE: Pattern[str]
class Linker(object):
class Linker:
def __init__(
self,
callbacks: Iterable[_Callback] = ...,

View File

@@ -15,7 +15,7 @@ INVISIBLE_REPLACEMENT_CHAR: str
# A html5lib Filter class
_Filter = Any
class Cleaner(object):
class Cleaner:
tags: Container[str]
attributes: _Attributes
styles: Container[str]

View File

@@ -30,7 +30,7 @@ DEF: Pattern[str]
_dict = dict # conflicts with attribute name
class FunctionMaker(object):
class FunctionMaker:
args: list[Text]
varargs: Text | None
varkw: Text | None

View File

@@ -6,17 +6,17 @@ from typing import Any, Type, TypeVar, Union, overload
_T = TypeVar("_T")
_Freezable = Union[str, datetime, date, timedelta]
class TickingDateTimeFactory(object):
class TickingDateTimeFactory:
def __init__(self, time_to_freeze: datetime, start: datetime) -> None: ...
def __call__(self) -> datetime: ...
class FrozenDateTimeFactory(object):
class FrozenDateTimeFactory:
def __init__(self, time_to_freeze: datetime) -> None: ...
def __call__(self) -> datetime: ...
def tick(self, delta: float | Real | timedelta = ...) -> None: ...
def move_to(self, target_datetime: _Freezable | None) -> None: ...
class StepTickTimeFactory(object):
class StepTickTimeFactory:
def __init__(self, time_to_freeze: datetime, step_width: float) -> None: ...
def __call__(self) -> datetime: ...
def tick(self, delta: timedelta | None = ...) -> None: ...

View File

@@ -18,7 +18,7 @@ def version_info() -> tuple[int, str, int, str, int, str, int, str, tuple[str, .
class error(Exception): ...
class Curl(object):
class Curl:
def close(self) -> None: ...
def setopt(self, option: int, value: Any) -> None: ...
def setopt_string(self, option: int, value: str) -> None: ...
@@ -34,7 +34,7 @@ class Curl(object):
# TODO(MichalPokorny): wat?
USERPWD: int
class CurlMulti(object):
class CurlMulti:
def close(self) -> None: ...
def add_handle(self, obj: Curl) -> None: ...
def remove_handle(self, obj: Curl) -> None: ...
@@ -44,7 +44,7 @@ class CurlMulti(object):
def info_read(self, max_objects: int = ...) -> tuple[int, list[Any], list[Any]]: ...
def socket_action(self, sockfd: int, ev_bitmask: int) -> tuple[int, int]: ...
class CurlShare(object):
class CurlShare:
def close(self) -> None: ...
def setopt(self, option: int, value: Any) -> Any: ...

View File

@@ -689,7 +689,7 @@ class Pipeline(Redis[_StrType], Generic[_StrType]):
def cluster(self, cluster_arg: str, *args: Any) -> Pipeline[_StrType]: ... # type: ignore[override]
def client(self) -> Any: ...
class Monitor(object):
class Monitor:
command_re: Pattern[str]
monitor_re: Pattern[str]
def __init__(self, connection_pool) -> None: ...

View File

@@ -128,6 +128,15 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
UnionFinder().visit(node.returns)
self.generic_visit(node)
class ObjectClassdefFinder(ast.NodeVisitor):
def visit_ClassDef(self, node: ast.ClassDef) -> None:
if any(isinstance(base, ast.Name) and base.id == "object" for base in node.bases):
errors.append(
f"{path}:{node.lineno}: Do not inherit from `object` explicitly, "
f"as all classes implicitly inherit from `object` in Python 3"
)
self.generic_visit(node)
class IfFinder(ast.NodeVisitor):
def visit_If(self, node: ast.If) -> None:
if (
@@ -146,6 +155,9 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
if path != Path("stdlib/typing_extensions.pyi"):
OldSyntaxFinder().visit(tree)
if not python_2_support_required:
ObjectClassdefFinder().visit(tree)
IfFinder().visit(tree)
return errors