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
bpo-12915: Add pkgutil.resolve_name #18310
Conversation
Some design questions:
I would also comment that requiring the name parts to be valid Python names isn't technically required and adds complexity, although I expect situations where it's a hindrance are few and far between. |
The word "deprecate" isn't used anywhere. The reason for preferring the new form is given in the documentation.
On what do you base this assertion? For example,
I don't find the current implementation too complex, and generally attributes are Python identifiers (though of course one might be able to get around that by overriding |
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.
Thanks for taking up this patch!
Some suggestions for the docs and unit tests.
For comparison, here are other implementations:
I think that Vinay’s solution using a regex has a nice balance of checking validity without the performance hit of calling for example |
Codecov Report
@@ Coverage Diff @@
## master #18310 +/- ##
==========================================
- Coverage 82.20% 82.12% -0.09%
==========================================
Files 1957 1955 -2
Lines 588968 584020 -4948
Branches 44401 44456 +55
==========================================
- Hits 484160 479607 -4553
+ Misses 95153 94767 -386
+ Partials 9655 9646 -9
Continue to review full report at Codecov.
|
I notice that Will you update pydoc and other modules to use this new function in a separate PR? |
Not as far as I know, because it doesn't especially make sense for entry points. It seemed reasonable to support this use case, and no reason not to allow it (although not useful for entry points, it could be useful in other contexts).
Yes, and possibly using more than one PR. |
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.
Not sure about allowing module:
, but in general +1!
Lib/pkgutil.py
Outdated
mod = importlib.import_module(modname) | ||
while parts: | ||
p = parts[0] | ||
s = '%s.%s' % (modname, p) |
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.
Minor: % formatting here and on line 679.
bpo-12915: Add pkgutil.resolve_name (pythonGH-18310)
https://bugs.python.org/issue12915