Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e816acf

Browse files
authored
Avoid unnecessary forward refs in class definitions (#10124)
1 parent 2775322 commit e816acf

5 files changed

Lines changed: 98 additions & 99 deletions

File tree

stdlib/enum.pyi

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,6 @@ def unique(enumeration: _EnumerationT) -> _EnumerationT: ...
208208

209209
_auto_null: Any
210210

211-
# subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
212-
class auto(IntFlag):
213-
_value_: Any
214-
@_magic_enum_attr
215-
def value(self) -> Any: ...
216-
def __new__(cls) -> Self: ...
217-
218211
class Flag(Enum):
219212
_name_: str | None # type: ignore[assignment]
220213
_value_: int
@@ -235,27 +228,6 @@ class Flag(Enum):
235228
__rand__ = __and__
236229
__rxor__ = __xor__
237230

238-
if sys.version_info >= (3, 11):
239-
# The body of the class is the same, but the base classes are different.
240-
class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases
241-
def __new__(cls, value: int) -> Self: ...
242-
def __or__(self, other: int) -> Self: ...
243-
def __and__(self, other: int) -> Self: ...
244-
def __xor__(self, other: int) -> Self: ...
245-
__ror__ = __or__
246-
__rand__ = __and__
247-
__rxor__ = __xor__
248-
249-
else:
250-
class IntFlag(int, Flag): # type: ignore[misc] # complaints about incompatible bases
251-
def __new__(cls, value: int) -> Self: ...
252-
def __or__(self, other: int) -> Self: ...
253-
def __and__(self, other: int) -> Self: ...
254-
def __xor__(self, other: int) -> Self: ...
255-
__ror__ = __or__
256-
__rand__ = __and__
257-
__rxor__ = __xor__
258-
259231
if sys.version_info >= (3, 11):
260232
class StrEnum(str, ReprEnum):
261233
def __new__(cls, value: str) -> Self: ...
@@ -289,3 +261,31 @@ if sys.version_info >= (3, 11):
289261
def global_enum(cls: _EnumerationT, update_str: bool = False) -> _EnumerationT: ...
290262
def global_enum_repr(self: Enum) -> str: ...
291263
def global_flag_repr(self: Flag) -> str: ...
264+
265+
if sys.version_info >= (3, 11):
266+
# The body of the class is the same, but the base classes are different.
267+
class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases
268+
def __new__(cls, value: int) -> Self: ...
269+
def __or__(self, other: int) -> Self: ...
270+
def __and__(self, other: int) -> Self: ...
271+
def __xor__(self, other: int) -> Self: ...
272+
__ror__ = __or__
273+
__rand__ = __and__
274+
__rxor__ = __xor__
275+
276+
else:
277+
class IntFlag(int, Flag): # type: ignore[misc] # complaints about incompatible bases
278+
def __new__(cls, value: int) -> Self: ...
279+
def __or__(self, other: int) -> Self: ...
280+
def __and__(self, other: int) -> Self: ...
281+
def __xor__(self, other: int) -> Self: ...
282+
__ror__ = __or__
283+
__rand__ = __and__
284+
__rxor__ = __xor__
285+
286+
# subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
287+
class auto(IntFlag):
288+
_value_: Any
289+
@_magic_enum_attr
290+
def value(self) -> Any: ...
291+
def __new__(cls) -> Self: ...

stdlib/multiprocessing/synchronize.pyi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ class Barrier(threading.Barrier):
1414
self, parties: int, action: Callable[[], object] | None = None, timeout: float | None = None, *ctx: BaseContext
1515
) -> None: ...
1616

17-
class BoundedSemaphore(Semaphore):
18-
def __init__(self, value: int = 1, *, ctx: BaseContext) -> None: ...
19-
2017
class Condition(AbstractContextManager[bool]):
2118
def __init__(self, lock: _LockLike | None = None, *, ctx: BaseContext) -> None: ...
2219
def notify(self, n: int = 1) -> None: ...
@@ -36,6 +33,14 @@ class Event:
3633
def clear(self) -> None: ...
3734
def wait(self, timeout: float | None = None) -> bool: ...
3835

36+
# Not part of public API
37+
class SemLock(AbstractContextManager[bool]):
38+
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
39+
def release(self) -> None: ...
40+
def __exit__(
41+
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
42+
) -> None: ...
43+
3944
class Lock(SemLock):
4045
def __init__(self, *, ctx: BaseContext) -> None: ...
4146

@@ -45,10 +50,5 @@ class RLock(SemLock):
4550
class Semaphore(SemLock):
4651
def __init__(self, value: int = 1, *, ctx: BaseContext) -> None: ...
4752

48-
# Not part of public API
49-
class SemLock(AbstractContextManager[bool]):
50-
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
51-
def release(self) -> None: ...
52-
def __exit__(
53-
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
54-
) -> None: ...
53+
class BoundedSemaphore(Semaphore):
54+
def __init__(self, value: int = 1, *, ctx: BaseContext) -> None: ...

stdlib/sqlite3/dbapi2.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,13 @@ class Cursor(Iterator[Any]):
390390
def __iter__(self) -> Self: ...
391391
def __next__(self) -> Any: ...
392392

393-
class DataError(DatabaseError): ...
394-
class DatabaseError(Error): ...
395-
396393
class Error(Exception):
397394
if sys.version_info >= (3, 11):
398395
sqlite_errorcode: int
399396
sqlite_errorname: str
400397

398+
class DatabaseError(Error): ...
399+
class DataError(DatabaseError): ...
401400
class IntegrityError(DatabaseError): ...
402401
class InterfaceError(Error): ...
403402
class InternalError(DatabaseError): ...

stubs/SQLAlchemy/sqlalchemy/sql/annotation.pyi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,15 @@ annotated_classes: dict[Incomplete, Incomplete]
118118

119119
# Everything below is dynamically generated at runtime
120120

121-
class AnnotatedAlias(AnnotatedAliasedReturnsRows, Alias): ...
121+
class AnnotatedFromClause(_SelectableAnnotatedFromClause, FromClause): ...
122122
class AnnotatedAliasedReturnsRows(AnnotatedFromClause, AliasedReturnsRows): ...
123+
class AnnotatedAlias(AnnotatedAliasedReturnsRows, Alias): ...
124+
class AnnotatedColumnElement(_ElementsAnnotatedColumnElement, ColumnElement[_T]): ...
125+
class AnnotatedFunctionElement(AnnotatedColumnElement[_T], FunctionElement): ... # type: ignore[misc]
126+
class AnnotatedFunction(AnnotatedFunctionElement[_T], Function): ... # type: ignore[misc]
127+
class AnnotatedGenericFunction(AnnotatedFunction[_T], GenericFunction): ... # type: ignore[misc]
123128
class AnnotatedAnsiFunction(AnnotatedGenericFunction[_T], AnsiFunction): ... # type: ignore[misc]
129+
class AnnotatedUnaryExpression(AnnotatedColumnElement[_T], UnaryExpression): ...
124130
class AnnotatedAsBoolean(AnnotatedUnaryExpression[_T], AsBoolean): ...
125131
class AnnotatedBinaryExpression(AnnotatedColumnElement[_T], BinaryExpression): ...
126132
class AnnotatedBindParameter(AnnotatedColumnElement[_T], BindParameter[_T]): ...
@@ -131,25 +137,20 @@ class AnnotatedCast(AnnotatedColumnElement[_T], Cast): ...
131137
class AnnotatedClauseList(Annotated, ClauseList): ...
132138
class AnnotatedCollationClause(AnnotatedColumnElement[_T], CollationClause): ...
133139
class AnnotatedCollectionAggregate(AnnotatedUnaryExpression[_T], CollectionAggregate): ...
134-
class AnnotatedColumn(AnnotatedColumnClause[_T], Column): ...
140+
class AnnotatedNamedColumn(AnnotatedColumnElement[_T], NamedColumn): ...
135141
class AnnotatedColumnClause(AnnotatedNamedColumn[_T], ColumnClause): ...
136-
class AnnotatedColumnElement(_ElementsAnnotatedColumnElement, ColumnElement[_T]): ...
142+
class AnnotatedColumn(AnnotatedColumnClause[_T], Column): ...
137143
class AnnotatedExists(AnnotatedUnaryExpression[_T], Exists): ...
138144
class AnnotatedExtract(AnnotatedColumnElement[_T], Extract): ...
139145
class AnnotatedFalse_(AnnotatedColumnElement[_T], False_): ...
140-
class AnnotatedFromClause(_SelectableAnnotatedFromClause, FromClause): ...
141146
class AnnotatedFromGrouping(AnnotatedFromClause, FromGrouping): ...
142-
class AnnotatedFunction(AnnotatedFunctionElement[_T], Function): ... # type: ignore[misc]
143147
class AnnotatedFunctionAsBinary(AnnotatedBinaryExpression[_T], FunctionAsBinary): ...
144-
class AnnotatedFunctionElement(AnnotatedColumnElement[_T], FunctionElement): ... # type: ignore[misc]
145148
class AnnotatedFunctionFilter(AnnotatedColumnElement[_T], FunctionFilter): ...
146-
class AnnotatedGenericFunction(AnnotatedFunction[_T], GenericFunction): ... # type: ignore[misc]
147149
class AnnotatedGrouping(AnnotatedColumnElement[_T], Grouping): ...
148150
class AnnotatedIndexExpression(AnnotatedBinaryExpression[_T], IndexExpression): ...
149151
class AnnotatedJoin(AnnotatedFromClause, Join): ...
150152
class AnnotatedLabel(AnnotatedColumnElement[_T], Label): ...
151153
class AnnotatedLateral(AnnotatedAliasedReturnsRows, Lateral): ...
152-
class AnnotatedNamedColumn(AnnotatedColumnElement[_T], NamedColumn): ...
153154
class AnnotatedNull(AnnotatedColumnElement[_T], Null): ...
154155
class AnnotatedOrderedSetAgg(AnnotatedGenericFunction[_T], OrderedSetAgg): ... # type: ignore[misc]
155156
class AnnotatedOver(AnnotatedColumnElement[_T], Over): ...
@@ -158,15 +159,14 @@ class AnnotatedScalarFunctionColumn(AnnotatedNamedColumn[_T], ScalarFunctionColu
158159
class AnnotatedScalarSelect(AnnotatedGrouping[_T], ScalarSelect): ...
159160
class AnnotatedSlice(AnnotatedColumnElement[_T], Slice): ...
160161
class AnnotatedSubquery(AnnotatedAliasedReturnsRows, Subquery): ...
161-
class AnnotatedTable(AnnotatedTableClause, Table): ...
162162
class AnnotatedTableClause(AnnotatedFromClause, TableClause): ...
163+
class AnnotatedTable(AnnotatedTableClause, Table): ...
163164
class AnnotatedTableSample(AnnotatedAliasedReturnsRows, TableSample): ...
164165
class AnnotatedTableValuedAlias(AnnotatedAlias, TableValuedAlias): ...
165166
class AnnotatedTableValuedColumn(AnnotatedNamedColumn[_T], TableValuedColumn): ...
166167
class AnnotatedTrue_(AnnotatedColumnElement[_T], True_): ...
167168
class AnnotatedTuple(AnnotatedColumnElement[_T], Tuple): ...
168169
class AnnotatedTypeCoerce(AnnotatedColumnElement[_T], TypeCoerce): ...
169-
class AnnotatedUnaryExpression(AnnotatedColumnElement[_T], UnaryExpression): ...
170170
class AnnotatedValues(AnnotatedFromClause, Values): ...
171171
class AnnotatedWithinGroup(AnnotatedColumnElement[_T], WithinGroup): ...
172172
class Annotated_CompileLabel(AnnotatedColumnElement[_T], _CompileLabel): ...

stubs/setuptools/pkg_resources/__init__.pyi

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ class Environment:
7373
def obtain(self, requirement: Requirement, installer: Callable[[Requirement], _T]) -> _T: ...
7474
def scan(self, search_path: Sequence[str] | None = None) -> None: ...
7575

76-
class DistInfoDistribution(Distribution):
77-
PKG_INFO: ClassVar[Literal["METADATA"]]
78-
EQEQ: ClassVar[Pattern[str]]
79-
8076
def parse_requirements(strs: str | Iterable[str]) -> Generator[Requirement, None, None]: ...
8177

8278
class Requirement:
@@ -133,50 +129,6 @@ def get_distribution(dist: _D) -> _D: ...
133129
@overload
134130
def get_distribution(dist: _PkgReqType) -> Distribution: ...
135131

136-
class Distribution(NullProvider, IResourceProvider, IMetadataProvider):
137-
PKG_INFO: ClassVar[str]
138-
location: str
139-
project_name: str
140-
@property
141-
def key(self) -> str: ...
142-
@property
143-
def extras(self) -> list[str]: ...
144-
@property
145-
def version(self) -> str: ...
146-
@property
147-
def parsed_version(self) -> tuple[str, ...]: ...
148-
py_version: str
149-
platform: str | None
150-
precedence: int
151-
def __init__(
152-
self,
153-
location: str | None = None,
154-
metadata: _MetadataType = None,
155-
project_name: str | None = None,
156-
version: str | None = None,
157-
py_version: str = ...,
158-
platform: str | None = None,
159-
precedence: int = 3,
160-
) -> None: ...
161-
@classmethod
162-
def from_location(
163-
cls, location: str, basename: str, metadata: _MetadataType = None, **kw: str | None | int
164-
) -> Distribution: ...
165-
@classmethod
166-
def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ...
167-
def activate(self, path: list[str] | None = None) -> None: ...
168-
def as_requirement(self) -> Requirement: ...
169-
def requires(self, extras: tuple[str, ...] = ()) -> list[Requirement]: ...
170-
def clone(self, **kw: str | int | None) -> Requirement: ...
171-
def egg_name(self) -> str: ... # type: ignore[override] # supertype's egg_name is a variable, not a method
172-
def __cmp__(self, other: Any) -> bool: ...
173-
def get_entry_info(self, group: str, name: str) -> EntryPoint | None: ...
174-
@overload
175-
def get_entry_map(self) -> dict[str, dict[str, EntryPoint]]: ...
176-
@overload
177-
def get_entry_map(self, group: str) -> dict[str, EntryPoint]: ...
178-
def load_entry_point(self, group: str, name: str) -> Any: ...
179-
180132
EGG_DIST: int
181133
BINARY_DIST: int
182134
SOURCE_DIST: int
@@ -276,6 +228,54 @@ class NullProvider:
276228
def metadata_listdir(self, name: str) -> list[str]: ...
277229
def run_script(self, script_name: str, namespace: dict[str, Any]) -> None: ...
278230

231+
class Distribution(NullProvider, IResourceProvider, IMetadataProvider):
232+
PKG_INFO: ClassVar[str]
233+
location: str
234+
project_name: str
235+
@property
236+
def key(self) -> str: ...
237+
@property
238+
def extras(self) -> list[str]: ...
239+
@property
240+
def version(self) -> str: ...
241+
@property
242+
def parsed_version(self) -> tuple[str, ...]: ...
243+
py_version: str
244+
platform: str | None
245+
precedence: int
246+
def __init__(
247+
self,
248+
location: str | None = None,
249+
metadata: _MetadataType = None,
250+
project_name: str | None = None,
251+
version: str | None = None,
252+
py_version: str = ...,
253+
platform: str | None = None,
254+
precedence: int = 3,
255+
) -> None: ...
256+
@classmethod
257+
def from_location(
258+
cls, location: str, basename: str, metadata: _MetadataType = None, **kw: str | None | int
259+
) -> Distribution: ...
260+
@classmethod
261+
def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ...
262+
def activate(self, path: list[str] | None = None) -> None: ...
263+
def as_requirement(self) -> Requirement: ...
264+
def requires(self, extras: tuple[str, ...] = ()) -> list[Requirement]: ...
265+
def clone(self, **kw: str | int | None) -> Requirement: ...
266+
def egg_name(self) -> str: ... # type: ignore[override] # supertype's egg_name is a variable, not a method
267+
def __cmp__(self, other: Any) -> bool: ...
268+
def get_entry_info(self, group: str, name: str) -> EntryPoint | None: ...
269+
@overload
270+
def get_entry_map(self) -> dict[str, dict[str, EntryPoint]]: ...
271+
@overload
272+
def get_entry_map(self, group: str) -> dict[str, EntryPoint]: ...
273+
def load_entry_point(self, group: str, name: str) -> Any: ...
274+
275+
class DistInfoDistribution(Distribution):
276+
PKG_INFO: ClassVar[Literal["METADATA"]]
277+
EQEQ: ClassVar[Pattern[str]]
278+
279279
class EggProvider(NullProvider):
280280
egg_root: str
281281

0 commit comments

Comments
 (0)