Skip to content

Commit d8baac2

Browse files
committed
[Model] Add set attributes _attrs in HelpScout objects
1 parent 102e4ab commit d8baac2

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented here.
44

5+
## [0.2.3] - 2019-07-16
6+
### Fixed
7+
- Setting attributes to HelpScout objects adds them to the attributes list.
8+
59
## [0.2.2] - 2019-07-12
610
### Fixed
711
- Send json data actually as json.

helpscout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from helpscout.client import HelpScout # noqa
22

33

4-
__version__ = '0.2.2'
4+
__version__ = '0.2.3'

helpscout/model.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ def cls(cls, entity_name, key):
7171
globals()[class_name] = cls = type(class_name, (cls,), {'key': key})
7272
return cls
7373

74+
def __setattr__(self, attr, value):
75+
"""Sets an attribute to an object and adds it to the attributes list.
76+
77+
Parameters
78+
----------
79+
attr: str
80+
value: object
81+
"""
82+
if attr == '_attrs':
83+
super(HelpScoutObject, self).__setattr__(attr, value)
84+
elif attr not in self._attrs:
85+
self._attrs = tuple(sorted(self._attrs + (attr,)))
86+
super(HelpScoutObject, self).__setattr__(attr, value)
87+
else:
88+
super(HelpScoutObject, self).__setattr__(attr, value)
89+
7490
def __reduce__(self):
7591
"""For pickling with HelpScoutObject."""
7692
class_attributes = self.__class__.__name__, self.key

0 commit comments

Comments
 (0)