'functools.total_ordering not working to add __gt__ even when I have __lt__ defined?

I have the following class:

@functools.total_ordering
class RepoVersion(Version):

    def __lt__(self, other) -> bool:
        if isinstance(other, Version):
            return self._compare_key < other._compare_key
        return NotImplemented

I expect totalordering to define __gt__ for me given __lt__. However I get an error in practice:

TypeError: '>' not supported between instances of 'RepoVersion' and 'Version'

Unless I also add __gt__ manually:

@functools.total_ordering
class RepoVersion(Version):

    def __lt__(self, other) -> bool:

        if isinstance(other, Version):
            return self._compare_key < other._compare_key
        return NotImplemented

    def __gt__(self, other) -> bool:
        if isinstance(other, Version):
            return self._compare_key > other._compare_key
        return NotImplemented

... but that seems redundant and is what I'm trying to avoid by adding the total_ordering. What's going on here?

Note Version here defines __eq__ and _compare_key but no other comparisons. I've omitted it for brevity but if it's relevant then the source code is here on GitHub



Solution 1:[1]

You're trying to import from the __pycache__ folder when the music.py file isn't in it.
Try import cogs.music.music instead.

Solution 2:[2]

Turns out I needed a __init__.py file in the cogs directory

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adid
Solution 2 ontley