Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TypeError when comparing VersionInfo to None #346

Copy link
Copy link
Closed
@cariad

Description

@cariad
Issue body actions

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugError, flaw or fault to produce incorrect or unexpected resultsError, flaw or fault to produce incorrect or unexpected results

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.