Skip to content

Commit

Permalink
stdlib: Use pos-only parameters for many Protocols
Browse files Browse the repository at this point in the history
Some of the fallout from PyCQA/flake8-pyi#442.

In each case, I looked at CPython to check how the protocol is being used.
  • Loading branch information
JelleZijlstra committed Nov 6, 2023
1 parent a5c1a4c commit ba45818
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion stdlib/_typeshed/wsgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from typing import Any, Protocol
from typing_extensions import TypeAlias

class _Readable(Protocol):
def read(self, size: int = ...) -> bytes: ...
def read(self, __size: int = ...) -> bytes: ...
# Optional: def close(self) -> object: ...

if sys.version_info >= (3, 11):
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_typeshed/xml.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ from typing import Any, Protocol

# As defined https://docs.python.org/3/library/xml.dom.html#domimplementation-objects
class DOMImplementation(Protocol):
def hasFeature(self, feature: str, version: str | None) -> bool: ...
def createDocument(self, namespaceUri: str, qualifiedName: str, doctype: Any | None) -> Any: ...
def createDocumentType(self, qualifiedName: str, publicId: str, systemId: str) -> Any: ...
def hasFeature(self, __feature: str, __version: str | None) -> bool: ...
def createDocument(self, __namespaceUri: str, __qualifiedName: str, __doctype: Any | None) -> Any: ...
def createDocumentType(self, __qualifiedName: str, __publicId: str, __systemId: str) -> Any: ...
2 changes: 1 addition & 1 deletion stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class _ActionsContainer:
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> None: ...

class _FormatterClass(Protocol):
def __call__(self, prog: str) -> HelpFormatter: ...
def __call__(self, *, prog: str) -> HelpFormatter: ...

class ArgumentParser(_AttributeHolder, _ActionsContainer):
prog: str
Expand Down
4 changes: 2 additions & 2 deletions stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ class _StreamWriter(Protocol):
def __call__(self, __stream: _WritableStream, __errors: str = ...) -> StreamWriter: ...

class _IncrementalEncoder(Protocol):
def __call__(self, errors: str = ...) -> IncrementalEncoder: ...
def __call__(self, __errors: str = ...) -> IncrementalEncoder: ...

class _IncrementalDecoder(Protocol):
def __call__(self, errors: str = ...) -> IncrementalDecoder: ...
def __call__(self, __errors: str = ...) -> IncrementalDecoder: ...

class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
_is_text_encoding: bool
Expand Down
2 changes: 1 addition & 1 deletion stdlib/compileall.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from typing import Any, Protocol
__all__ = ["compile_dir", "compile_file", "compile_path"]

class _SupportsSearch(Protocol):
def search(self, string: str) -> Any: ...
def search(self, __string: str) -> Any: ...

if sys.version_info >= (3, 10):
def compile_dir(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/email/headerregistry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ if sys.version_info >= (3, 8):
class _HeaderParser(Protocol):
max_count: ClassVar[Literal[1] | None]
@staticmethod
def value_parser(value: str) -> TokenList: ...
def value_parser(__value: str) -> TokenList: ...
@classmethod
def parse(cls, value: str, kwds: dict[str, Any]) -> None: ...
def parse(cls, __value: str, __kwds: dict[str, Any]) -> None: ...

class HeaderRegistry:
registry: dict[str, type[_HeaderParser]]
Expand Down
4 changes: 2 additions & 2 deletions stdlib/imghdr.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ __all__ = ["what"]

class _ReadableBinary(Protocol):
def tell(self) -> int: ...
def read(self, size: int) -> bytes: ...
def seek(self, offset: int) -> Any: ...
def read(self, __size: int) -> bytes: ...
def seek(self, __offset: int) -> Any: ...

@overload
def what(file: StrPath | _ReadableBinary, h: None = None) -> str | None: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/imp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _FileLike(Protocol):
def read(self) -> str | bytes: ...
def close(self) -> Any: ...
def __enter__(self) -> Any: ...
def __exit__(self, typ: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> Any: ...
def __exit__(self, __typ: type[BaseException] | None, __exc: BaseException | None, __tb: TracebackType | None) -> Any: ...

# PathLike doesn't work for the pathname argument here
def load_source(name: str, pathname: str, file: _FileLike | None = None) -> types.ModuleType: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/importlib/abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ if sys.version_info >= (3, 9):
# which is not the case.
@overload
@abstractmethod
def open(self, mode: Literal["r", "w"] = "r", *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ...
def open(self, __mode: Literal["r", "w"] = "r", *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ...
@overload
@abstractmethod
def open(self, mode: Literal["rb", "wb"]) -> IO[bytes]: ...
def open(self, __mode: Literal["rb", "wb"]) -> IO[bytes]: ...
@property
@abstractmethod
def name(self) -> str: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class SimpleNamespace:
def __delattr__(self, __name: str) -> None: ...

class _LoaderProtocol(Protocol):
def load_module(self, fullname: str) -> ModuleType: ...
def load_module(self, __fullname: str) -> ModuleType: ...

class ModuleType:
__name__: str
Expand Down

0 comments on commit ba45818

Please sign in to comment.