Closed trim21 closed 11 months ago
Yeah; this would certainly help the usability of these objects.
Since I just recently dropped support for Python <3.8, I started an effort to integrate typing directly in to the py
files and get rid of these pyi
files....although, I'm encountering a lot of issues because this also requires the typing to comply with Python 3.8 syntax. So, I'm not sure if I'm going to continue this effort right now...
At any rate, while adding these attribute types is relatively trivial, it also means this project needs to stay abreast of new values as they are added (and maybe even old values are they are removed...)...and there isn't any way to say which attributes apply to which versions of qBittorrent...and if an attribute changes types altogether, there isn't a way to represent that for different versions for qBittorrent.
That said, I don't think those inherently negate the value of adding these types....after all, these APIs return quite a bit of JSON, so this is a large hole in the typing effort in general.
I'll experiment a bit with this and see what the best solution is.
Here's a quick and dirty solution that could be used in the interim though:
from dataclasses import dataclass
from qbittorrentapi import Client
@dataclass
class Tracker:
url: str
msg: str
num_downloaded: int
num_leeches: int
num_peers: int
num_seeds: int
status: int
tier: int
client = Client()
trackers = [Tracker(**t) for t in client.torrents_trackers(...)]
Yeah; this would certainly help the usability of these objects.
Since I just recently dropped support for Python <3.8, I started an effort to integrate typing directly in to the
py
files and get rid of thesepyi
files....although, I'm encountering a lot of issues because this also requires the typing to comply with Python 3.8 syntax. So, I'm not sure if I'm going to continue this effort right now...At any rate, while adding these attribute types is relatively trivial, it also means this project needs to stay abreast of new values as they are added (and maybe even old values are they are removed...)...and there isn't any way to say which attributes apply to which versions of qBittorrent...and if an attribute changes types altogether, there isn't a way to represent that for different versions for qBittorrent.
That said, I don't think those inherently negate the value of adding these types....after all, these APIs return quite a bit of JSON, so this is a large hole in the typing effort in general.
I'll experiment a bit with this and see what the best solution is.
Here's a quick and dirty solution that could be used in the interim though:
from dataclasses import dataclass from qbittorrentapi import Client @dataclass class Tracker: url: str msg: str num_downloaded: int num_leeches: int num_peers: int num_seeds: int status: int tier: int client = Client() trackers = [Tracker(**t) for t in client.torrents_trackers(...)]
Yes, this is what I'm doing in my personal project.
I find add typing is more complex than I thought.
I'n not sure if this is the right approach, but I hope to add dict field to some list item, for example, tracker.
Currently these field are typed as
int | str | bool | Sequence[JsonValueT] | Mapping[str, JsonValueT] | None
, make it hard to use.