if TYPE_CHECKING:
+ # from https://github.com/python/mypy/issues/14858
+
@overload
- def setdefault(self, key: _KT) -> _VT | None:
+ def setdefault(
+ self: MutableDict[_KT, Optional[_T]], key: _KT, value: None = None
+ ) -> Optional[_T]:
...
@overload
def setdefault(self, key: _KT, value: _VT) -> _VT:
...
- def setdefault(self, key: _KT, value: _VT | None = None) -> _VT | None:
+ def setdefault(self, key: _KT, value: object = None) -> object:
...
else:
@compat_typing.dataclass_transform(
field_specifiers=(
- MappedColumn[Any],
- RelationshipProperty[Any],
- Composite[Any],
- ColumnProperty[Any],
- Synonym[Any],
+ MappedColumn,
+ RelationshipProperty,
+ Composite,
+ ColumnProperty,
+ Synonym,
mapped_column,
relationship,
composite,
@compat_typing.dataclass_transform(
field_specifiers=(
- MappedColumn[Any],
- RelationshipProperty[Any],
- Composite[Any],
- ColumnProperty[Any],
- Synonym[Any],
+ MappedColumn,
+ RelationshipProperty,
+ Composite,
+ ColumnProperty,
+ Synonym,
mapped_column,
relationship,
composite,
"""A dictionary that is not publicly mutable."""
def __new__(cls, *args: Any) -> FacadeDict[Any, Any]:
- new = dict.__new__(cls)
+ new = ImmutableDictBase.__new__(cls)
return new
def copy(self) -> NoReturn:
from typing import Optional
from typing import Set
from typing import Tuple
+from typing import TYPE_CHECKING
from typing import TypeVar
from typing import Union
+from ..util.typing import Self
+
_T = TypeVar("_T", bound=Any)
_S = TypeVar("_S", bound=Any)
_KT = TypeVar("_KT", bound=Any)
class ImmutableDictBase(ReadOnlyContainer, Dict[_KT, _VT]):
+ if TYPE_CHECKING:
+
+ def __new__(cls, *args: Any) -> Self:
+ ...
+
+ def __init__(cls, *args: Any):
+ ...
+
def _readonly(self, *arg: Any, **kw: Any) -> NoReturn:
self._immutable()
class immutabledict(ImmutableDictBase[_KT, _VT]):
def __new__(cls, *args):
- new = dict.__new__(cls)
+ new = ImmutableDictBase.__new__(cls)
dict.__init__(new, *args)
return new
if not __d:
return self
- new = dict.__new__(self.__class__)
+ new = ImmutableDictBase.__new__(self.__class__)
dict.__init__(new, self)
dict.update(new, __d) # type: ignore
return new
if not __d and not kw:
return self
- new = dict.__new__(self.__class__)
+ new = ImmutableDictBase.__new__(self.__class__)
dict.__init__(new, self)
if __d:
dict.update(new, __d) # type: ignore
for d in dicts:
if d:
if new is None:
- new = dict.__new__(self.__class__)
+ new = ImmutableDictBase.__new__(self.__class__)
dict.__init__(new, self)
dict.update(new, d) # type: ignore
if new is None: