-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[Technical Question] Weird behavior of a functional - Is it intended ? #13196
Comments
Taking a quick look, it appears to only be called on a path or a URL, neither of which can have a version. |
I did the same and came to the same conclusion, could do with better documentation on it's limitations, but appears to be correctly being used. |
@pfmoore If I use my debugger and do I was having fun to see if I could correct the regex to be more generic, it would probably make smthg like this: import re
from typing import Optional, Tuple
def _strip_extras(path: str) -> Tuple[str, Optional[str]]:
pattern = r"^(.+?)\[(.*?)\](?:([=~><!]+)(.+))?$"
match = re.match(pattern, path)
if match:
base_name = match.group(1)
bracketed_part = f"[{match.group(2)}]"
# Handles cases with/without versions
version_specifier = (match.group(3) or "") + (match.group(4) or "")
return f"{base_name}{version_specifier}", bracketed_part
return path, None
if __name__ == "__main__":
print(f"{_strip_extras('package_name[extra]')=}") # ('package_name', '[extra]')
print(f"{_strip_extras('package_name[extra]==1.0.0')=}") # ('package_name==1.0.0', '[extra]')
print(f"{_strip_extras('package_name[extra]>=1.0.0')=}") # ('package_name>=1.0.0', '[extra]')
print(f"{_strip_extras('package_name[extra]<=1.0.0')=}") # ('package_name<=1.0.0', '[extra]')
print(f"{_strip_extras('package_name[extra]=~1.0.0')=}") # ('package_name=~1.0.0', '[extra]') |
IMO, where possible we should be moving away from pip specific regex and to relying on packaging instead. >>> from packaging.requirements import Requirement
>>> Requirement('package_name[extra]==1.0.0').extras
{'extra'} |
Oh that's nice ! What do you think @pfmoore ? |
Fix what exactly? Is this causing an issue or failure for something? Just because it's called in a way that doesn't seem intuitive doesn't mean that code path results in an error. |
it's propagating The problem is most certainly in my code/changes, but still this could be a "silent issue" in most cases. |
I would say you're welcome to try and "fix" functions like this, but be aware that code later on might be assuming that requirements are provided this way, so it might end up requiring a refactor of more parts of the codebase. It's important that optimizations like #12095 aren't accidentally broken (though, I will verify complex real world cases for any PR submitted that affects resolution). |
I agree with @notatallshaw that we should be using
Can you give an example? Not just that In
Again, the value So either the problem is that you're using It's not that we like having code like this, but it's been round unchanged for 7 years, if not longer - we may not even have been using |
Description
I have a quick technical question on this function: https://github.com/pypa/pip/blob/f5ff4fa27dd991f209f2a9f9283a7c1561221b2c/src/pip/_internal/req/constructors.py#L44C1-L53C34
It's being used to separate
package_name[extra]
intopackage_name
and[extra]
However its seems that this function (the regex specifically) does not work if you use a version specifier
==1.0.0
or>=1.0.0
, is it intended ?Expected behavior
The expected behavior would probably be, instead of
getting this:
pip version
Any
Python version
Any
OS
Any
How to Reproduce
See above
Output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: