-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Add dynamicscope items, keys, values, update, and iter #566
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #566 +/- ##
=======================================
Coverage 70.92% 70.92%
=======================================
Files 287 287
Lines 25710 25710
Branches 3643 3643
=======================================
Hits 18234 18234
Misses 6385 6385
Partials 1091 1091 |
Before we go this route, I'd like it if someone investigated the change between Py2 and Py3 to see if that really is the problem. It may be (but probably unlikely) that everyone assumes |
Both frame.f_locals and PyFrame_GetLocals say mapping. The traceback module uses For reasons I don't understand the Dynamicscope has Py_TPFLAGS_DICT_SUBCLASS set but not Py_TPFLAGS_MAPPING so it is a dict according to PyDict_Check. Idk how it passes the PyMapping_Check yet. Edit: Looks like just having an mp_subscript makes it pass that. Either way it at least needs to implement the |
I'll need to spend some time tracking this down to make sure we do the right
thing, but here is an issue to start your research if you wanna do it in
parallel with me:
https://bugs.python.org/issue5945
…On Fri, Jan 10, 2025 at 7:52 PM frmdstryr ***@***.***> wrote:
Both frame.f_locals
<https://docs.python.org/3/reference/datamodel.html#frame.f_locals> and
PyFrame_GetLocals
<https://docs.python.org/3/c-api/frame.html#c.PyFrame_GetLocals> say
mapping.
The traceback module uses list(frame.f_locals)
<https://github.com/python/cpython/blob/main/Lib/traceback.py#L1507> and
locals.items()
<https://github.com/python/cpython/blob/main/Lib/traceback.py#L315-L316>
which should be part of mapping at least according to collections.abc
<https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes>
.
For reasons I don't understand the Dynamicscope has
Py_TPFLAGS_DICT_SUBCLASS
<https://github.com/nucleic/enaml/blob/main/enaml/src/dynamicscope.cpp#L820>
set but not Py_TPFLAGS_MAPPING so it is a dict according to PyDict_Check.
Idk how it passes the PyMapping_Check yet.
Either way it at least needs to implement the tp_iter?
—
Reply to this email directly, view it on GitHub
<#566 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABBQSJYRELWZXV4CBWGSWL2KB2MZAVCNFSM6AAAAABU7I557KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBUHE4TIMRTHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
It looks like But then the mapping functions go on to call other methods that should exist on the object (just read thru the rest of the functions below |
Agree on PyMapping_Check. I looked through bytecodes.c for uses of locals and it seems to only use PyObject_SetItem, PyObject_GetItemOptional, and PyObject_DelItem. So what do you think should be done? |
For each of the added methods, I would like a clear view of when they are expected to be used and why we are fine paying the price of creating a dict. |
To do this properly, and without over-allocating upfront, we'll need to produce a proper iterator over the dynamic scope. Likely the easiest way to do this is to keep a Those python methods don't need to be fast, they just need to be present. |
But one other thing to keep in mind is that I would also be fine with |
@sccolbert do you have any specific concern regarding tracing ? I do not really see what could happen from exposing interfaces that do not allow to mutate the scope.
A frozen items like in Python 2 would probably be sufficient for debugging purposes and hopefully the limitations won't be noticed. |
This at least fixes #565 and makes ipython embed work in an expression/event handler.
I don't think doing the full scope (walking parents and getting members) is necessary but I can try that if needed.