-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
py: Add support for function doc strings. #14045
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Damien George <damien@micropython.org>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14045 +/- ##
=======================================
Coverage 98.36% 98.36%
=======================================
Files 161 161
Lines 21084 21084
=======================================
Hits 20739 20739
Misses 345 345 ☔ View full report in Codecov by Sentry. |
|
Code size report: |
| #if MICROPY_ENABLE_DOC_STRING | ||
| // look for the first statement | ||
| mp_parse_node_t pn = pns->nodes[3]; // the function body/suite | ||
| if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_suite_block_stmts)) { |
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.
This check already seems to be done by check_for_doc_string?
i.e. this whole thing could be a call to check_for_doc_string, the only difference is how it emits the store of __doc__ ?
| // compile the function definition | ||
| compile_funcdef_lambdef(comp, fscope, pns->nodes[1], PN_typedargslist); | ||
|
|
||
| #if MICROPY_ENABLE_DOC_STRING |
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.
Can we update the comment in mpconfig.h to explain that this enables docstrings on functions, modules, and classes?
(I think we should keep them as one combined option)
|
I really want to find a way to make this use less RAM for functions that don't have doc strings. Because at the moment all functions increase by 1 GC block size, regardless of whether they use the new doc string slot. But I don't know how to do that in a simple way. It probably requires a separate function type like If we can find a way to do that then we could enable this feature on the large ports, because it would only cost something if docs strings are used. Also could extend things to allow any attribute to be stored to a function object, not just the |
|
Out of interest wrt to the Micropython-stubs project I'd like to understand what the goal is for this feature Is it targeting stdlib/micropython code, frozen (. Mpy) code, or regular micropython.py modules? I assume the interface would be the cpython style Is there something similar considered for modules or classes.? |
This PR adds support for function doc strings. It's disabled by default.
TODO: