-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py: Implement __dict__ for class #2843
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
Conversation
Thanks for the PR. Please can you give some background on why you needed this feature? Also, it would be much simpler to just return |
I'm using MicroPython to provide Python as a script language for the Godot game engine. Basically Godot engine works with a gui where you drop nodes, which you can connect to a script class. from godot import exposed, export
from godot.bindings import Node2D
@exposed
class Player(Node2D):
name = export(str, default=”Samuel”)
def _ready(self):
pass Loading this module will result from the Godot point of view of making available the To implement this, I should iterate over all the class fields and retrieve the ones which are instance of
That's what instance's By the way I fixed my patch to support the case where |
Thanks for the detailed description of your usecase, it's really helpful to know how people use MicroPython! And thanks for selecting MicroPython as your embedding engine, that's one of the area we'd like to have more traction, but lack resources. But we'd really like people selecting us as their Python implementation not because we're doing it like CPython, but because we're doing it differently (because otherwise, using CPython is the most obvious way, and we won't be able to compete with CPython even if we could, but we don't have any agenda like that). This is described in more detail in https://github.com/micropython/micropython/wiki/ContributorGuidelines , and should be insightful read.
You can, without any patching and fully compatibly with CPython:
|
Thanks for writting MicroPython then 😃
Problem is using |
btw I don't understand why travis flag the build is considered as failed given the tests seems to have passed... |
Check the build log in Travis:
|
@stinos thanks for the help ! Now everything is fine 😄 |
py/objtype.c
Outdated
mp_obj_dict_store(attr_dict, map->table[i].key, map->table[i].value); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you simply do attr_dict = self->locals_dict
(as long as locals_dict is not NULL)? It's not 100% the same as CPython because you can edit the returned dict and it'll modify the class, but it's much simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to stay close to #1757 code, beside not copying locals_dict
means you can modify it only if it is not null, which is pretty strange from the Python point of view (e.g. sometime you can modify __dict__
, sometime the modification is not taken into account...)
Anyway I've simplify my implementation to follow you're advice. I you prefer the first solution in the end, just tell me and I'll revert ;-)
@dpgeorge Updated following your advices |
Let me be straight: I'm -1 on this. And the reason is right there - in the submitter's own words:
So, how |
This was implemented in 28370c0 |
Based on #1757 PR