Skip to content

Commit

Permalink
WIP: Simplify python wrapper code 5
Browse files Browse the repository at this point in the history
  • Loading branch information
astitcher committed Jan 10, 2025
1 parent 66214c1 commit a9e44eb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions python/proton/_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Wrapper(object):
"""

__slots__ = ["_impl", "_attrs"]

def __init__(self, impl: Any = None) -> None:
attrs = None
try:
Expand All @@ -56,14 +58,14 @@ def __init__(self, impl: Any = None) -> None:
record = self.get_context(impl)
attrs = pn_record_get_py(record)
finally:
self.__dict__["_impl"] = impl
self.__dict__["_attrs"] = attrs
self._impl = impl
self._attrs = attrs

def Uninitialized(self) -> bool:
return self._attrs == {}

def __getattr__(self, name: str) -> Any:
attrs = self.__dict__["_attrs"]
attrs = self._attrs
if attrs and name in attrs:
return attrs[name]
else:
Expand All @@ -73,12 +75,12 @@ def __setattr__(self, name: str, value: Any) -> None:
if hasattr(self.__class__, name):
object.__setattr__(self, name, value)
else:
attrs = self.__dict__["_attrs"]
attrs = self._attrs
if attrs is not None:
attrs[name] = value

def __delattr__(self, name: str) -> None:
attrs = self.__dict__["_attrs"]
attrs = self._attrs
if attrs:
del attrs[name]

Expand Down

0 comments on commit a9e44eb

Please sign in to comment.