Skip to content

atmel-samd & esp8266: Behavior difference with class attribute getter, doesn't work on ESP8266 port. #68

Description

@tdicola

I noticed something odd, the convention we're using for the bus device and register class only seems to work on the SAMD21 port. For the ESP8266 port it appears a class attribute that has a getter function doesn't call the getter. Here's a simple repro, try running the following code on both the latest SAMD21 and ESP8266 version of this port:

class TestAttribute:

        def __init__(self):
                pass

        def __get__(self, obj, objtype=None):
                return "Hello world!"

class TestClass:

        test_attr = TestAttribute()

        def __init__(self):
                pass

foo = TestClass()
print(foo.test_attr)

On SAMD21 calling foo.test_attr returns and prints 'Hello world' as expected:

tony-macbook:Downloads tony$ ampy run test2.py 
Hello world!

However on ESP8266 the same code instead prints out the class attribute info, i.e. it's not calling the __get__ function:

tony-macbook:Downloads tony$ ampy run test2.py 
<TestAttribute object at 3fff0df0>

You can explicitly call the get function and it does work, try running:

>>> foo.test_attr.__get__(foo)
'Hello world!'

However using the attribute as intended (just reading the value and not explicitly calling get) doesn't work and curiously differs from the SAMD21 port behavior.

Priority-wise I think this issue is a little higher than others. We can't use the register classes in drivers if their behavior differs between the ports. Perhaps there is a port specific micropython language flag to that differs between the ports?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions