-
Notifications
You must be signed in to change notification settings - Fork 9
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
parse_version() should accept None and empty strings #10
Comments
aboutcode-org/univers#10 - parse_version() should accept None and empty strings Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
@pombredanne Also, now that we have |
To add, |
Adding version("") should work , as assigning "" to a variable to initialize an empty string in Python. |
aboutcode-org/univers#10 - parse_version() should accept None and empty strings Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
aboutcode-org/univers#10 - parse_version() should accept None and empty strings Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
aboutcode-org/univers#10 - parse_version() should accept None and empty strings Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
>>> from univers.versions import Version
>>> Version(None)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-dece84ce917a> in <module>
----> 1 Version(None)
~/Contrib/univers/src/univers/versions.py in __init__(self, string, normalized_string, value)
5 _inst_dict['normalized_string'] = normalized_string
6 _inst_dict['value'] = value
----> 7 self.__attrs_post_init__()
~/Contrib/univers/src/univers/versions.py in __attrs_post_init__(self)
59
60 def __attrs_post_init__(self):
---> 61 normalized_string = self.normalize(self.string)
62 if not self.is_valid(normalized_string):
63 raise InvalidVersion(f"{self.string!r} is not a valid {self.__class__!r}")
~/Contrib/univers/src/univers/versions.py in normalize(cls, string)
86 """
87 # FIXME: Is removing spaces and strip v the right thing to do?
---> 88 return remove_spaces(string).rstrip("v")
89
90 @classmethod
~/Contrib/univers/src/univers/utils.py in remove_spaces(string)
7
8 def remove_spaces(string):
----> 9 return "".join(string.split())
10
11
AttributeError: 'NoneType' object has no attribute 'split' |
IMHO that's a feature. When would a |
Thanks, but None or empty would be the same... and I am not sure this would make any sense. |
Please see #33 |
This causes problems in vulnerablecode when the importers/improvers get incomplete data as it is currently the case for some of them. This should be handled in the calling code in vulnerablecode ( PR aboutcode-org/vulnerablecode#1215 ). |
@janniclas Thanks! |
None is what I did in my workaround to fix the problem when I encountered it in vulnerablecode. |
@pombredanne I just added a test case to the previously linked PR, maybe this is also helpful for you :) |
In https://github.com/nexB/univers/blob/63bd5aec16ec95b5b811ede638ac225f3ab1f6c6/src/univers/versions.py#L286
we should let parse_version() accept None and empty strings, otherwise the calling code has too much work to do.
The text was updated successfully, but these errors were encountered: