trim21 / transmission-rpc

https://transmission-rpc.readthedocs.io/en/stable/
MIT License
139 stars 34 forks source link

Inconsistent number types of certain float-typed properties #456

Closed cheeseandcereal closed 1 month ago

cheeseandcereal commented 1 month ago

Description

Due to the limitations of json, there is no distinction in the protocol for different types of numbers (i.e. float vs int)

This means that when parsing the response field of a number from the RPC, if it's a 'double' field (or documented as 'float' in this library), it may not always return a float. This typically happens when a 'double' number as defined in the rpc is either flat 0 or 1.

For example:

type(client.get_torrents()[0].percent_done)
<class 'int'>

This is inconsistent with the documented types. I.e. for this example: https://github.com/trim21/transmission-rpc/blob/57c064f6b740b67be1ed7c5afad5ce18476616f4/transmission_rpc/torrent.py#L562

This can result in some edge case issues where applications actually depend on this number to be of a particular type, and/or not flip between int and float

For any value that's documented as a float, this library should explicitly 'cast' it as a float to avoid this inconsistent typing.

i.e.

 return float(self.fields["percentDone"])
trim21 commented 1 month ago

can you send a PR?

cheeseandcereal commented 1 month ago

Yeah i can make a PR some time later and send it over