Skip to content

Fix __get__ in CPython. #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions adafruit_ble/advertising/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def __init__(self, *, advertising_data_type):
self._adt = advertising_data_type

def __get__(self, obj, cls):
if obj is None:
return self
if self._adt not in obj.data_dict:
return None
return str(obj.data_dict[self._adt], "utf-8")
Expand All @@ -157,6 +159,8 @@ def __init__(self, struct_format, *, advertising_data_type):
self._adt = advertising_data_type

def __get__(self, obj, cls):
if obj is None:
return self
if self._adt not in obj.data_dict:
return None
return struct.unpack(self._format, obj.data_dict[self._adt])[0]
Expand All @@ -174,6 +178,8 @@ def __init__(self, cls, attribute_name, *, advertising_data_type, **kwargs):
self._kwargs = kwargs

def __get__(self, obj, cls):
if obj is None:
return self
# Return None if our object is immutable and the data is not present.
if not obj.mutable and self._adt not in obj.data_dict:
return None
Expand Down
2 changes: 2 additions & 0 deletions adafruit_ble/advertising/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def __init__(self, key, value_format, field_names=None):
self.field_names = field_names

def __get__(self, obj, cls):
if obj is None:
return self
if self._key not in obj.manufacturer_data.data:
return None
packed = obj.manufacturer_data.data[self._key]
Expand Down