TypeError when comparing VersionInfo to None
See original GitHub issueSituation
semver raises TypeError
when comparing VersionInfo
to None
.
To Reproduce
from dataclasses import dataclass
from typing import Optional
from semver import VersionInfo
@dataclass
class MyData:
data: Optional[VersionInfo]
a = MyData(data=VersionInfo(1))
b = MyData(data=None)
assert a != b
Traceback (most recent call last):
File "/home/cariad/startifact/version.py", line 15, in <module>
assert a != b
File "<string>", line 4, in __eq__
File "/home/cariad/startifact/.venv/lib/python3.10/site-packages/semver.py", line 200, in wrapper
raise TypeError(
TypeError: other type <class 'NoneType'> must be in (<class 'semver.VersionInfo'>, <class 'dict'>, <class 'tuple'>, <class 'list'>, <class 'str'>, <class 'bytes'>)
Expected Behavior
I expect a comparison of VersionInfo
to None
to return False
.
For reference, this example with strings does work:
from dataclasses import dataclass
from typing import Optional
@dataclass
class MyData:
data: Optional[str]
a = MyData(data="foo")
b = MyData(data=None)
assert a != b
Environment
- OS: Linux
- Python version: 3.10
- Version of semver library: 2.13.0
Additional context
- I ❤️ semver – thanks for all your work!
- I’m happy to work on a pull request. Let me know?
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Python 3: TypeError thrown when comparing different types ...
Python 3: TypeError thrown when comparing different types, especially comparing None versus something else #9107.
Read more >How to throw exception when comparing with None on Python ...
I want to somehow force expressions 3, 4 and 5 to throw TypeError (same as in expression 1). Python 3.4 is nearly there...
Read more >Using semver — python-semver 2.10.2 documentation
You get a TypeError if your dictionary contains invalid keys. ... VersionInfo(*t) VersionInfo(major=3, minor=5, patch=6, prerelease=None, build=None).
Read more >Built-in Types — Python 3.11.1 documentation
Non -identical instances of a class normally compare as non-equal unless the class defines the __eq__() method. Instances of a class cannot be...
Read more >What's new in 1.5.0 (September 19, 2022) - Pandas
To avoid this behavior, the specifying the value numeric_only=None has been deprecated, and will be removed in a future version of pandas. In...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tomschr Ah, you’re amazing! Thank you! 😄
Closing now! This issue isn’t blocking me (I’ve forgotten how I worked around it, but everything’s working so 🤷) so I’m not waiting on that dev release. 🚀