question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError when comparing VersionInfo to None

See original GitHub issue

Situation

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

  1. I ❤️ semver – thanks for all your work!
  2. I’m happy to work on a pull request. Let me know?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cariadcommented, Jan 21, 2022

@tomschr Ah, you’re amazing! Thank you! 😄

1reaction
cariadcommented, Jan 11, 2022

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. 🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found