Skip to content

Commit d5c5cdf

Browse files
authored
Merge pull request #69 from tannewt/check_for_obj_none
Fix __get__ in CPython.
2 parents 2682f51 + 70502dc commit d5c5cdf

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

adafruit_ble/advertising/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def __init__(self, *, advertising_data_type):
143143
self._adt = advertising_data_type
144144

145145
def __get__(self, obj, cls):
146+
if obj is None:
147+
return self
146148
if self._adt not in obj.data_dict:
147149
return None
148150
return str(obj.data_dict[self._adt], "utf-8")
@@ -157,6 +159,8 @@ def __init__(self, struct_format, *, advertising_data_type):
157159
self._adt = advertising_data_type
158160

159161
def __get__(self, obj, cls):
162+
if obj is None:
163+
return self
160164
if self._adt not in obj.data_dict:
161165
return None
162166
return struct.unpack(self._format, obj.data_dict[self._adt])[0]
@@ -174,6 +178,8 @@ def __init__(self, cls, attribute_name, *, advertising_data_type, **kwargs):
174178
self._kwargs = kwargs
175179

176180
def __get__(self, obj, cls):
181+
if obj is None:
182+
return self
177183
# Return None if our object is immutable and the data is not present.
178184
if not obj.mutable and self._adt not in obj.data_dict:
179185
return None

adafruit_ble/advertising/standard.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def __init__(self, key, value_format, field_names=None):
224224
self.field_names = field_names
225225

226226
def __get__(self, obj, cls):
227+
if obj is None:
228+
return self
227229
if self._key not in obj.manufacturer_data.data:
228230
return None
229231
packed = obj.manufacturer_data.data[self._key]

0 commit comments

Comments
 (0)