Replace Mapping with types.MappingProxyType (#6013)

Mark `Signature.parameters` and `.return_annotation` as read-only properties
This commit is contained in:
Bas van Beek
2021-09-09 09:58:53 +02:00
committed by GitHub
parent 6188a3eec7
commit b9e1d7d522
5 changed files with 16 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
import sys
import types
from typing import Any, Callable, Generic, Iterable, Mapping, Tuple, Type, TypeVar, overload
from typing_extensions import Protocol
@@ -77,7 +78,7 @@ class Field(Generic[_T]):
hash: bool | None
init: bool
compare: bool
metadata: Mapping[Any, Any]
metadata: types.MappingProxyType[Any, Any]
if sys.version_info >= (3, 10):
kw_only: bool
def __init__(

View File

@@ -1,4 +1,5 @@
import sys
import types
from datetime import datetime as _datetime
from email._header_value_parser import (
AddressList,
@@ -11,7 +12,7 @@ from email._header_value_parser import (
)
from email.errors import MessageDefect
from email.policy import Policy
from typing import Any, Iterable, Mapping, Tuple, Type
from typing import Any, Iterable, Tuple, Type
class BaseHeader(str):
@property
@@ -74,7 +75,7 @@ class MIMEVersionHeader:
class ParameterizedMIMEHeader:
@property
def params(self) -> Mapping[str, Any]: ...
def params(self) -> types.MappingProxyType[str, Any]: ...
@classmethod
def parse(cls, value: str, kwds: dict[str, Any]) -> None: ...

View File

@@ -1,7 +1,8 @@
import sys
import types
from abc import ABCMeta
from builtins import property as _builtins_property
from typing import Any, Iterator, Mapping, Type, TypeVar
from typing import Any, Iterator, Type, TypeVar
_T = TypeVar("_T")
_S = TypeVar("_S", bound=Type[Enum])
@@ -17,7 +18,7 @@ class EnumMeta(ABCMeta):
def __contains__(self: Type[Any], member: object) -> bool: ...
def __getitem__(self: Type[_T], name: str) -> _T: ...
@_builtins_property
def __members__(self: Type[_T]) -> Mapping[str, _T]: ...
def __members__(self: Type[_T]) -> types.MappingProxyType[str, _T]: ...
def __len__(self) -> int: ...
_member_names_: list[str] # undocumented
_member_map_: dict[str, Enum] # undocumented

View File

@@ -1,21 +1,7 @@
import sys
import types
from _typeshed import SupportsItems, SupportsLessThan
from typing import (
Any,
Callable,
Generic,
Hashable,
Iterable,
Mapping,
NamedTuple,
Sequence,
Set,
Sized,
Tuple,
Type,
TypeVar,
overload,
)
from typing import Any, Callable, Generic, Hashable, Iterable, NamedTuple, Sequence, Set, Sized, Tuple, Type, TypeVar, overload
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -86,7 +72,7 @@ class partialmethod(Generic[_T]):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
class _SingleDispatchCallable(Generic[_T]):
registry: Mapping[Any, Callable[..., _T]]
registry: types.MappingProxyType[Any, Callable[..., _T]]
def dispatch(self, cls: Any) -> Callable[..., _T]: ...
# @fun.register(complex)
# def _(arg, verbose=False): ...

View File

@@ -1,5 +1,6 @@
import enum
import sys
import types
from _typeshed import Self
from collections import OrderedDict
from collections.abc import Awaitable, Callable, Generator, Mapping, Sequence, Set
@@ -120,11 +121,11 @@ class Signature:
def __init__(self, parameters: Sequence[Parameter] | None = ..., *, return_annotation: Any = ...) -> None: ...
# TODO: can we be more specific here?
empty: object
parameters: Mapping[str, Parameter]
@property
def parameters(self) -> types.MappingProxyType[str, Parameter]: ...
# TODO: can we be more specific here?
return_annotation: Any
@property
def return_annotation(self) -> Any: ...
def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
def bind_partial(self, *args: Any, **kwargs: Any) -> BoundArguments: ...
def replace(self: Self, *, parameters: Sequence[Parameter] | None = ..., return_annotation: Any = ...) -> Self: ...