Skip to content

Commit a0b4195

Browse files
authored
stdlib: fix many attributes which are read-only at runtime but read-write in the stub (#7395)
1 parent 46da0b8 commit a0b4195

File tree

17 files changed

+104
-50
lines changed

17 files changed

+104
-50
lines changed

stdlib/email/_header_value_parser.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,14 @@ class InvalidMailbox(TokenList):
181181
token_type: str
182182
@property
183183
def display_name(self) -> None: ...
184-
local_part: None
185-
domain: None
186-
route: None
187-
addr_spec: None
184+
@property
185+
def local_part(self) -> None: ...
186+
@property
187+
def domain(self) -> None: ...
188+
@property
189+
def route(self) -> None: ...
190+
@property
191+
def addr_spec(self) -> None: ...
188192

189193
class Domain(TokenList):
190194
token_type: str

stdlib/hmac.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ else:
2626
class HMAC:
2727
digest_size: int
2828
block_size: int
29-
name: str
29+
@property
30+
def name(self) -> str: ...
3031
def __init__(self, key: bytes, msg: ReadableBuffer | None = ..., digestmod: _DigestMod = ...) -> None: ...
3132
def update(self, msg: ReadableBuffer) -> None: ...
3233
def digest(self) -> bytes: ...

stdlib/http/cookies.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ def _unquote(str: str) -> str: ...
2121
class CookieError(Exception): ...
2222

2323
class Morsel(dict[str, Any], Generic[_T]):
24-
value: str
25-
coded_value: _T
26-
key: str
24+
@property
25+
def value(self) -> str: ...
26+
@property
27+
def coded_value(self) -> _T: ...
28+
@property
29+
def key(self) -> str: ...
2730
def __init__(self) -> None: ...
2831
if sys.version_info >= (3, 7):
2932
def set(self, key: str, val: str, coded_val: _T) -> None: ...

stdlib/importlib/machinery.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class ModuleSpec:
2222
submodule_search_locations: list[str] | None
2323
loader_state: Any
2424
cached: str | None
25-
parent: str | None
25+
@property
26+
def parent(self) -> str | None: ...
2627
has_location: bool
2728
def __eq__(self, other: object) -> bool: ...
2829

stdlib/importlib/metadata/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ if sys.version_info >= (3, 10):
4242
from importlib.metadata._meta import PackageMetadata as PackageMetadata
4343
def packages_distributions() -> Mapping[str, list[str]]: ...
4444

45-
class PackageNotFoundError(ModuleNotFoundError): ...
45+
class PackageNotFoundError(ModuleNotFoundError):
46+
@property
47+
def name(self) -> str: ... # type: ignore[override]
4648

4749
class _EntryPointBase(NamedTuple):
4850
name: str

stdlib/inspect.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,12 @@ class Parameter:
357357

358358
class BoundArguments:
359359
arguments: OrderedDict[str, Any]
360-
args: tuple[Any, ...]
361-
kwargs: dict[str, Any]
362-
signature: Signature
360+
@property
361+
def args(self) -> tuple[Any, ...]: ...
362+
@property
363+
def kwargs(self) -> dict[str, Any]: ...
364+
@property
365+
def signature(self) -> Signature: ...
363366
def __init__(self, signature: Signature, arguments: OrderedDict[str, Any]) -> None: ...
364367
def apply_defaults(self) -> None: ...
365368
def __eq__(self, other: object) -> bool: ...

stdlib/multiprocessing/dummy/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import threading
33
import weakref
44
from queue import Queue as Queue
55
from typing import Any, Callable, Iterable, Mapping, Sequence
6+
from typing_extensions import Literal
67

78
from .connection import Pipe as Pipe
89

@@ -39,7 +40,8 @@ class DummyProcess(threading.Thread):
3940
_parent: threading.Thread
4041
_pid: None
4142
_start_called: int
42-
exitcode: int | None
43+
@property
44+
def exitcode(self) -> Literal[0] | None: ...
4345
def __init__(
4446
self,
4547
group: Any = ...,

stdlib/pathlib.pyi

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ if sys.version_info >= (3, 9):
2020
__all__ = ["PurePath", "PurePosixPath", "PureWindowsPath", "Path", "PosixPath", "WindowsPath"]
2121

2222
class PurePath(PathLike[str]):
23-
parts: tuple[str, ...]
24-
drive: str
25-
root: str
26-
anchor: str
27-
name: str
28-
suffix: str
29-
suffixes: list[str]
30-
stem: str
23+
@property
24+
def parts(self) -> tuple[str, ...]: ...
25+
@property
26+
def drive(self) -> str: ...
27+
@property
28+
def root(self) -> str: ...
29+
@property
30+
def anchor(self) -> str: ...
31+
@property
32+
def name(self) -> str: ...
33+
@property
34+
def suffix(self) -> str: ...
35+
@property
36+
def suffixes(self) -> list[str]: ...
37+
@property
38+
def stem(self) -> str: ...
3139
def __new__(cls: type[Self], *args: StrPath) -> Self: ...
3240
def __hash__(self) -> int: ...
3341
def __eq__(self, other: object) -> bool: ...

stdlib/pydoc.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ class Helper:
200200
symbols: dict[str, str]
201201
topics: dict[str, str | tuple[str, ...]]
202202
def __init__(self, input: IO[str] | None = ..., output: IO[str] | None = ...) -> None: ...
203-
input: IO[str]
204-
output: IO[str]
203+
@property
204+
def input(self) -> IO[str]: ...
205+
@property
206+
def output(self) -> IO[str]: ...
205207
def __call__(self, request: str | Helper | object = ...) -> None: ...
206208
def interact(self) -> None: ...
207209
def getline(self, prompt: str) -> str: ...

stdlib/shlex.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ class shlex(Iterable[str]):
2929
lineno: int
3030
token: str
3131
eof: str
32-
punctuation_chars: str
32+
if sys.version_info >= (3, 7):
33+
@property
34+
def punctuation_chars(self) -> str: ...
35+
else:
36+
punctuation_chars: str
3337
def __init__(
3438
self,
3539
instream: str | TextIO | None = ...,

0 commit comments

Comments
 (0)