diff --git a/pynmea2/nmea.py b/pynmea2/nmea.py index a7c13d0..2398042 100644 --- a/pynmea2/nmea.py +++ b/pynmea2/nmea.py @@ -1,6 +1,10 @@ import re import operator from functools import reduce +from logging import getLogger + + +log = getLogger() class ParseError(ValueError): @@ -149,10 +153,12 @@ def parse(line, check=False): def __getattr__(self, name): #pylint: disable=invalid-name t = type(self) - try: - i = t.name_to_idx[name] - except KeyError: - raise AttributeError(name) + + if name not in t.name_to_idx: + log.debug("%s has no attribute %s", self.__class__.__name__, name) + return None + i = t.name_to_idx[name] + f = t.fields[i] if i < len(self.data): v = self.data[i] diff --git a/test/test_pynmea.py b/test/test_pynmea.py index b1867c6..317f189 100644 --- a/test/test_pynmea.py +++ b/test/test_pynmea.py @@ -25,8 +25,7 @@ def test_checksum(): def test_attribute(): msg = pynmea2.parse(data) - with pytest.raises(AttributeError): - msg.foobar + assert msg.foobar is None def test_fail():