python-dictattr
Advanced tools
+30
-17
@@ -7,6 +7,6 @@ #!/usr/bin/env python3 | ||
| __author__ = "ChenyangGao <https://chenyanggao.github.io>" | ||
| __version__ = (0, 0, 3) | ||
| __version__ = (0, 0, 4) | ||
| __all__ = [ | ||
| "odict", "AttrDict", "MapAttr", "MuMapAttr", | ||
| "DictAttr", "ChainDictAttr", "UserDictAttr", | ||
| "odict", "AttrDict", "MapAttr", "MuMapAttr", "DictAttr", | ||
| "ChainDictAttr", "UserDictAttr", "PriorityUserDictAttr", | ||
| ] | ||
@@ -128,10 +128,32 @@ | ||
| class UserDictAttr(UserDict[K, V]): | ||
| class UserDictAttr(UserDict): | ||
| def __getattr__(self, attr, /): | ||
| try: | ||
| return self[attr] | ||
| except KeyError as e: | ||
| raise AttributeError(attr) from e | ||
| def __getitem__(self, key, /): | ||
| d = super().__getitem__(key) | ||
| if isinstance(d, Mapping) and not isinstance(d, __class__): # type: ignore | ||
| return type(self)(d) | ||
| return d | ||
| def __repr__(self, /) -> str: | ||
| cls = type(self) | ||
| name = cls.__qualname__ | ||
| if (module := cls.__module__) != "__main__": | ||
| name = f"{module}.{name}" | ||
| return f"{name}.of({self.data!r})" | ||
| @classmethod | ||
| def of(cls, m: Mapping, /) -> Self: | ||
| self = cls() | ||
| self.__dict__["data"] = m # type: ignore | ||
| self.__dict__["data"] = m | ||
| return self | ||
| class PriorityUserDictAttr(UserDictAttr): | ||
| def __delattr__(self, attr, /): | ||
@@ -141,10 +163,4 @@ try: | ||
| except KeyError: | ||
| try: | ||
| super().__delattr__(attr) | ||
| except KeyError: | ||
| raise AttributeError(attr) | ||
| super().__delattr__(attr) | ||
| def __getattr__(self, attr, /): | ||
| return getattr(self.data, attr) | ||
| def __getattribute__(self, attr, /): | ||
@@ -158,7 +174,4 @@ if attr in ("__dict__", "data") or attr == f"__{attr.strip('_')}__": | ||
| def __getitem__(self, key, /) -> V | Self: # type: ignore | ||
| d = super().__getitem__(key) | ||
| if type(d) is dict: | ||
| return type(self)(d) | ||
| return d | ||
| def __getattr__(self, attr, /): | ||
| raise AttributeError(attr) | ||
@@ -165,0 +178,0 @@ def __setattr__(self, attr, val, /): |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: python-dictattr | ||
| Version: 0.0.3 | ||
| Version: 0.0.4 | ||
| Summary: Python dictattr. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-dictattr |
+1
-1
| [tool.poetry] | ||
| name = "python-dictattr" | ||
| version = "0.0.3" | ||
| version = "0.0.4" | ||
| description = "Python dictattr." | ||
@@ -5,0 +5,0 @@ authors = ["ChenyangGao <wosiwujm@gmail.com>"] |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
8273
4.54%130
7.44%