-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
py/modsys: Implement sys.intern. #13123
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
Code size report:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #13123 +/- ##
=======================================
Coverage 98.40% 98.40%
=======================================
Files 159 159
Lines 21075 21075
=======================================
Hits 20738 20738
Misses 337 337 ☔ View full report in Codecov by Sentry. |
py/mpconfig.h
Outdated
@@ -1434,6 +1434,12 @@ typedef double mp_float_t; | |||
#define MICROPY_PY_SYS_EXECUTABLE (0) | |||
#endif | |||
|
|||
// Whether to provide "sys.identity", implemented simply as returning the argument passed | |||
// since strings are already interned as qstr. |
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.
I'm guessing this should say "sys.intern".
Also, not all strings are qstrs. We could actually implement this function by calling the existing mp_obj_str_intern_checked()
. That has the benefit of raising an exception if the argument isn't a string (matching CPython).
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.
I'm guessing this should say "sys.intern".
Fixed.
Also, not all strings are qstrs. We could actually implement this function by calling the existing mp_obj_str_intern_checked()
Yeah was in doubt to use 'most strings are interned' but I missed the existence of that function, changed + added test
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.
I think this comment still needs fixing. Simply Whether to provide "sys.intern"
would probably be enough.
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.
Right. Must have left my head at home today.
b02d6a2
to
5c2443e
Compare
Signed-off-by: stijn <[email protected]>
See #6164 (comment) for backgroud; with the sys module now not being extensible anymore there's no other option than implementing this in C, as far as I can tell.