Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
args: [--fix=lf]
- id: check-case-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3 # must match requirements-tests.txt
rev: v0.11.2 # must match requirements-tests.txt
hooks:
- id: ruff
name: Run ruff on stubs, tests and scripts
Expand Down
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ packaging==24.2
pathspec>=0.11.1
pre-commit
# Required by create_baseline_stubs.py. Must match .pre-commit-config.yaml.
ruff==0.9.3
ruff==0.11.2
stubdefaulter==0.1.0
termcolor>=2.3
tomli==2.2.1
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ class structseq(Generic[_T_co]):
# The second parameter will accept a dict of any kind without raising an exception,
# but only has any meaning if you supply it a dict where the keys are strings.
# https://github.com/python/typeshed/pull/6560#discussion_r767149830
def __new__(cls: type[Self], sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> Self: ...
def __new__(cls: type[Self], sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> Self: ... # noqa: PYI019
if sys.version_info >= (3, 13):
def __replace__(self: Self, **kwargs: Any) -> Self: ...
def __replace__(self: Self, **kwargs: Any) -> Self: ... # noqa: PYI019
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably do a similar thing to typing.pyi here and use the fully qualified typing_extensions.Self to avoid having to add these noqa comments? (Same for __new__ immediately above)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try it. Maybe Self = TypeVar("Self") at line 40 isn't needed anymore.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Self = TypeVar("Self") at line 40 isn't needed anymore.

I think it is, because we use it in other modules for metaclasses (typing.Self is not allowed in metaclass methods)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick search it's still used in 2 openpyxl modules for metaclasses.


# Superset of typing.AnyStr that also includes LiteralString
AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001
Expand Down
2 changes: 1 addition & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
def setdefault(self, k: _Never, default: object) -> object: ...
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
def pop(self, k: _Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def update(self: _T, m: _T, /) -> None: ...
def update(self, m: typing_extensions.Self, /) -> None: ...
def __delitem__(self, k: _Never) -> None: ...
def items(self) -> dict_items[str, object]: ...
def keys(self) -> dict_keys[str, object]: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
def setdefault(self, k: Never, default: object) -> object: ...
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def update(self: _T, m: _T, /) -> None: ...
def update(self, m: Self, /) -> None: ...
def items(self) -> dict_items[str, object]: ...
def keys(self) -> dict_keys[str, object]: ...
def values(self) -> dict_values[str, object]: ...
Expand Down
6 changes: 3 additions & 3 deletions stubs/PyYAML/yaml/representer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ from _typeshed import Incomplete, ReadableBuffer, SupportsItems
from collections.abc import Callable, Iterable, Mapping
from types import BuiltinFunctionType, FunctionType, ModuleType
from typing import Any, ClassVar, NoReturn, TypeVar
from typing_extensions import Self

from yaml.error import YAMLError as YAMLError
from yaml.nodes import MappingNode as MappingNode, Node as Node, ScalarNode as ScalarNode, SequenceNode as SequenceNode

_T = TypeVar("_T")
_R = TypeVar("_R", bound=BaseRepresenter)

class RepresenterError(YAMLError): ...

Expand All @@ -25,9 +25,9 @@ class BaseRepresenter:
def represent(self, data) -> None: ...
def represent_data(self, data) -> Node: ...
@classmethod
def add_representer(cls: type[_R], data_type: type[_T], representer: Callable[[_R, _T], Node]) -> None: ...
def add_representer(cls, data_type: type[_T], representer: Callable[[Self, _T], Node]) -> None: ...
@classmethod
def add_multi_representer(cls: type[_R], data_type: type[_T], representer: Callable[[_R, _T], Node]) -> None: ...
def add_multi_representer(cls, data_type: type[_T], representer: Callable[[Self, _T], Node]) -> None: ...
def represent_scalar(self, tag: str, value, style: str | None = None) -> ScalarNode: ...
def represent_sequence(self, tag: str, sequence: Iterable[Any], flow_style: bool | None = None) -> SequenceNode: ...
def represent_mapping(
Expand Down
10 changes: 5 additions & 5 deletions stubs/protobuf/google/protobuf/internal/containers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
from typing import Any, Protocol, SupportsIndex, TypeVar, overload
from typing_extensions import Self

from google.protobuf.descriptor import Descriptor
from google.protobuf.internal.message_listener import MessageListener
Expand All @@ -10,7 +11,6 @@ _T = TypeVar("_T")
_K = TypeVar("_K", bound=bool | int | str)
_ScalarV = TypeVar("_ScalarV", bound=bool | int | float | str | bytes)
_MessageV = TypeVar("_MessageV", bound=Message)
_M = TypeVar("_M")

class _ValueChecker(Protocol[_T]):
def CheckValue(self, proposed_value: _T) -> _T: ...
Expand All @@ -33,7 +33,7 @@ class RepeatedScalarFieldContainer(BaseContainer[_ScalarV]):
def append(self, value: _ScalarV) -> None: ...
def insert(self, key: int, value: _ScalarV) -> None: ...
def extend(self, elem_seq: Iterable[_ScalarV] | None) -> None: ...
def MergeFrom(self: _M, other: _M | Iterable[_ScalarV]) -> None: ...
def MergeFrom(self, other: Self | Iterable[_ScalarV]) -> None: ...
def remove(self, elem: _ScalarV) -> None: ...
def pop(self, key: int = -1) -> _ScalarV: ...
@overload
Expand All @@ -49,7 +49,7 @@ class RepeatedCompositeFieldContainer(BaseContainer[_MessageV]):
def append(self, value: _MessageV) -> None: ...
def insert(self, key: int, value: _MessageV) -> None: ...
def extend(self, elem_seq: Iterable[_MessageV]) -> None: ...
def MergeFrom(self: _M, other: _M | Iterable[_MessageV]) -> None: ...
def MergeFrom(self, other: Self | Iterable[_MessageV]) -> None: ...
def remove(self, elem: _MessageV) -> None: ...
def pop(self, key: int = -1) -> _MessageV: ...
def __delitem__(self, key: int | slice) -> None: ...
Expand All @@ -73,7 +73,7 @@ class ScalarMap(MutableMapping[_K, _ScalarV]):
def get(self, key: _K, default: None = None) -> _ScalarV | None: ...
@overload
def get(self, key: _K, default: _ScalarV | _T) -> _ScalarV | _T: ...
def MergeFrom(self: _M, other: _M): ...
def MergeFrom(self, other: Self): ...
def InvalidateIterators(self) -> None: ...
def GetEntryClass(self) -> GeneratedProtocolMessageType: ...

Expand All @@ -96,6 +96,6 @@ class MessageMap(MutableMapping[_K, _MessageV]):
@overload
def get(self, key: _K, default: _MessageV | _T) -> _MessageV | _T: ...
def get_or_create(self, key: _K) -> _MessageV: ...
def MergeFrom(self: _M, other: _M): ...
def MergeFrom(self, other: Self): ...
def InvalidateIterators(self) -> None: ...
def GetEntryClass(self) -> GeneratedProtocolMessageType: ...
11 changes: 4 additions & 7 deletions stubs/protobuf/google/protobuf/message.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Sequence
from typing import Any, TypeVar
from typing import Any
from typing_extensions import Self

from .descriptor import Descriptor, FieldDescriptor
Expand All @@ -9,8 +9,6 @@ class Error(Exception): ...
class DecodeError(Error): ...
class EncodeError(Error): ...

_M = TypeVar("_M", bound=Message) # message type (of self)

class Message:
DESCRIPTOR: Descriptor
def __deepcopy__(self, memo: Any = None) -> Self: ...
Expand All @@ -26,12 +24,11 @@ class Message:
def SerializeToString(self, *, deterministic: bool = ...) -> bytes: ...
def SerializePartialToString(self, *, deterministic: bool = ...) -> bytes: ...
def ListFields(self) -> Sequence[tuple[FieldDescriptor, Any]]: ...
# The TypeVar must be bound to `Message` or we get mypy errors, so we cannot use `Self` for `HasExtension` & `ClearExtension`
def HasExtension(self: _M, field_descriptor: _ExtensionFieldDescriptor[_M, Any]) -> bool: ...
def ClearExtension(self: _M, field_descriptor: _ExtensionFieldDescriptor[_M, Any]) -> None: ...
def HasExtension(self, field_descriptor: _ExtensionFieldDescriptor[Self, Any]) -> bool: ...
def ClearExtension(self, field_descriptor: _ExtensionFieldDescriptor[Self, Any]) -> None: ...
# The TypeVar must be bound to `Message` or we get mypy errors, so we cannot use `Self` for `Extensions`
@property
def Extensions(self: _M) -> _ExtensionDict[_M]: ...
def Extensions(self) -> _ExtensionDict[Self]: ...
def ByteSize(self) -> int: ...
@classmethod
def FromString(cls, s: bytes) -> Self: ...
Expand Down