diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-25 17:08:48 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-30 14:04:52 -0400 |
commit | 4e754a8914a1c2c16c97bdf363d2e24bfa823730 (patch) | |
tree | db723242b4e4c0d4c7f15c167857dd79fdfa6ccb /lib/sqlalchemy/util/_py_collections.py | |
parent | dba480ebaf89c0b5ea787661583de9da3928920f (diff) | |
download | sqlalchemy-4e754a8914a1c2c16c97bdf363d2e24bfa823730.tar.gz |
pep-484: the pep-484ening, SQL part three
hitting DML which is causing us to open up the
ColumnCollection structure a bit, as we do put anonymous
column expressions with None here. However, we still want
Table /TableClause to have named column collections that
don't return None, so parametrize the "key" in this
collection also.
* rename some "immutable" elements to "readonly". we change
the contents of immutablecolumncollection underneath, so it's
not "immutable"
Change-Id: I2593995a4e5c6eae874bed5bf76117198be8ae97
Diffstat (limited to 'lib/sqlalchemy/util/_py_collections.py')
-rw-r--r-- | lib/sqlalchemy/util/_py_collections.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/sqlalchemy/util/_py_collections.py b/lib/sqlalchemy/util/_py_collections.py index d50352930..1016871aa 100644 --- a/lib/sqlalchemy/util/_py_collections.py +++ b/lib/sqlalchemy/util/_py_collections.py @@ -29,37 +29,45 @@ _KT = TypeVar("_KT", bound=Any) _VT = TypeVar("_VT", bound=Any) -class ImmutableContainer: +class ReadOnlyContainer: __slots__ = () + def _readonly(self, *arg: Any, **kw: Any) -> NoReturn: + raise TypeError( + "%s object is immutable and/or readonly" % self.__class__.__name__ + ) + def _immutable(self, *arg: Any, **kw: Any) -> NoReturn: raise TypeError("%s object is immutable" % self.__class__.__name__) def __delitem__(self, key: Any) -> NoReturn: - self._immutable() + self._readonly() def __setitem__(self, key: Any, value: Any) -> NoReturn: - self._immutable() + self._readonly() def __setattr__(self, key: str, value: Any) -> NoReturn: - self._immutable() + self._readonly() -class ImmutableDictBase(ImmutableContainer, Dict[_KT, _VT]): - def clear(self) -> NoReturn: +class ImmutableDictBase(ReadOnlyContainer, Dict[_KT, _VT]): + def _readonly(self, *arg: Any, **kw: Any) -> NoReturn: self._immutable() + def clear(self) -> NoReturn: + self._readonly() + def pop(self, key: Any, default: Optional[Any] = None) -> NoReturn: - self._immutable() + self._readonly() def popitem(self) -> NoReturn: - self._immutable() + self._readonly() def setdefault(self, key: Any, default: Optional[Any] = None) -> NoReturn: - self._immutable() + self._readonly() def update(self, *arg: Any, **kw: Any) -> NoReturn: - self._immutable() + self._readonly() class immutabledict(ImmutableDictBase[_KT, _VT]): |