Skip to content
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

make TorrentState comparable with str #267

Merged
merged 2 commits into from
Jul 13, 2023
Merged

make TorrentState comparable with str #267

merged 2 commits into from
Jul 13, 2023

Conversation

trim21
Copy link
Contributor

@trim21 trim21 commented Jul 13, 2023

assert TorrentState.MOVING == 'moving'

@trim21 trim21 changed the title make TorrentState comparable with str make TorrentState comparable with str Jul 13, 2023
@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #267 (3178c48) into main (d74ae48) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #267   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines         1957      1957           
  Branches       568       568           
=========================================
  Hits          1957      1957           
Impacted Files Coverage Δ
src/qbittorrentapi/definitions.py 100.00% <100.00%> (ø)

- Make `APINames` and `TorrentState` effectively a `StrEnum`
- Make `TrackerStatus` effectively a `IntEnum`
- This allows the enum members to be treated as though they were a str or int
@rmartin16
Copy link
Owner

This is a good idea; thanks. At first, this looked a bit strange to me...but this is exactly what the Enum docs recommend for this and even introduced StrEnum in stdlib in Python 3.11.

I perpetuated this idea to APINames and TrackerStatus as well. This mostly does what I expect...although, something like print(str(TorrentState.ERROR)) literally prints TorrentState.ERROR...when I was expecting error... 🤷🏼‍♂️

I was also getting errors from mypy stubtest when I included str and int in the base classes in the pyi files....the solution seemed non-obvious but excluding seems to work just as well.

@rmartin16 rmartin16 merged commit e79b646 into rmartin16:main Jul 13, 2023
@trim21 trim21 deleted the str-enum branch July 14, 2023 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants