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
Use iskeyword and str.isidentifier for "is FQCN" #73279
Use iskeyword and str.isidentifier for "is FQCN" #73279
Conversation
We already have an |
I've taken a prompt look and it seems that this helper doesn't replicate the stdlib behavior so I'm not sure if we want to reuse it for FQCNs. |
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 all for tightening this up to delegate to stdlib, but a few questions:
- why expose this as public API (and esp in module_utils, since modules should never need it)?
- should we just wait for 2.12 so we don't need the 2.x fallback?
- if we are doing for 2.11, the regex needs to be compiled- this gets called A LOT
Honestly, I wasn't sure where to put it, just wanted a separate compat module. The dependency resolver rewrite (#72591) will need it, ideally through calling
I wanted to move it out of #72591 so I thought it'd be better to do it sooner than later.
This is probably unnecessary — it's already cached internally: https://github.com/python/cpython/blob/c92cd0f/Lib/re.py#L285 / https://github.com/python/cpython/blob/2.7/Lib/re.py#L234-L241. |
Unless you've got an immediate concrete need for it independently of |
There's no guarantee the compiled pattern will remain in the cache. The docs state:
Looking at the source for both CPython 2.7 and 3.9, the LRU cache size is fixed at 512 entries. So while it's likely to stay cached, we shouldn't assume that. |
2a4a868
to
bcf1e04
Compare
@nitzmahone @mattclay I moved the shim into |
|
||
return all( | ||
# NOTE: keywords and identifiers are different in differnt Pythons | ||
not iskeyword(ns_or_name) and is_python_identifier(ns_or_name) |
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 could use a changelog. We might also want to document this in the developing_collections page or improve error messages to give a better clue about what might be wrong.
ansible-galaxy:
ERROR! Invalid collection name 'def.coll', name must be in the format <namespace>.<collection>.
Please make sure namespace and collection name contains characters from [a-zA-Z0-9_] only.
Using a now-invalid collection:
[WARNING]: errors were encountered during the plugin load for def.coll.my_module: ['invalid collection name (must be of the form namespace.collection): def.coll']
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.
Fair enough. But I think that changing the error message should go to a separate PR. The resolver already uses this code in one place anyway...
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.
Yeah, but in a very limited way. You could initialize + build + install the tarfile + use it, and it would work. I'm fine with changing the error later though.
SUMMARY
This is extracted from #72591.
ISSUE TYPE
COMPONENT NAME
N/A
ADDITIONAL INFORMATION
N/A
N/A