Skip to content
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

Customize attribute access for object #2761

Closed
wants to merge 2 commits into from
Closed

Customize attribute access for object #2761

wants to merge 2 commits into from

Conversation

dmazzella
Copy link
Contributor

No description provided.

@dmazzella
Copy link
Contributor Author

dmazzella commented Jan 5, 2017

@dpgeorge #2755 how fix this?

@dmazzella
Copy link
Contributor Author

@dpgeorge @pfalcon
in cPy:

>>> class A:
...     pass
...
>>> a = A()
>>> object.__setattr__(a, "a", 1)
>>> a
<__main__.A object at 0x6ffffa982e8>
>>> a.a
1
>>>

in uPy:

>>> class A:
...     pass
...
...
...
>>> a = A()
>>> object.__setattr__(a, "a", 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument should be a 'object' not a 'A'
>>>

@dmazzella
Copy link
Contributor Author

dmazzella commented Jan 5, 2017

if i add this check to runtime.c:

if (arg0_type != self->type
            #if MICROPY_PY_OBJECT_METHODS_DELATTRS_SETATTRS
            && !mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(arg0_type), MP_OBJ_FROM_PTR(&mp_type_object))
            #endif
            ) { ...

but not directly subclass "object":

>>> class A:
...     pass
...
...
...
>>> a = A()
>>> object.__setattr__(a, "a", 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument should be a 'object' not a 'A'
>>>

with subclass:

>>> class A(object):
...     pass
...
...
...
>>> a = A()
>>> object.__setattr__(a, "a", 1)
1
>>>

@dmazzella dmazzella closed this Jan 6, 2017
@dmazzella dmazzella deleted the customize_attribute_access_for_object branch January 6, 2017 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant