Closed bland328 closed 3 months ago
Hmm....thanks for letting me know. I've had similar issues recently with mypy (see https://github.com/rmartin16/qbittorrent-api/pull/467 as an example)....however, there are unresolved issues in mypy that are creating these problems.
I should be able to look further in to this later but are you able to see if recent previous versions of pylance also throw these errors? I've noticed these different type checkers tend to make changes in tandem....so, I wonder if they all did something recently related to wrapped functions....
As for qbittorrent-api's use of functools.wraps
....I believe I introduced all of this about 9 months ago...but mypy (and maybe now pylance too) is complaining about it. In researching the issue, I've seen other projects implement workarounds but none that I thought I could use here...
Happy to help! Pylance versions v2024.7.1
(current), v2024.6.1
, v2024.3.2
and 2023.12.1
(6 months old) all demonstrate the problem; if you'd like me to go back farther, just say the word.
Also, before today, I don't think my local copy of qbittorrent-api had been updated in about a year, so the 9-month-ago change you mentioned makes sense.
Some potential good news: I found a Pylance issue titled functools.wraps broken for complex class decorator for versions after 2023.02.40, and it is true that if I downgrade to 2023.02.40 (about a year old), the problem goes away.
And in that discussion, there's a suggestion on how to fix the issue with a code change.
Assuming you aren't already using that approach, perhaps it would make both Pylance and mypy happy.
Thanks for the confirmation and the research. I don't think any of this is going to work, though, unfortunately.
Moreover, I only implemented functools.wraps
so the RTD docs would automatically copy the docstrings around for me....but all this code duplication is on the list of things I wouldn't have added anyway if I could do it all over again.
Sooo, I think the "fix" here will just be to remove the wraps
decorators and duplicate the documentation as well...
@bland328, I created #472 to resolve this. If you're interested in testing this, you can install these changes with the pip
command below:
python -m pip install git+https://github.com/rmartin16/qbittorrent-api@remove-wraps
v2024.7.64 is now published with this fix.
Describe the bug
I recently updated qbittorrent-api (from what previous version, I can't say), and find that Visual Studio/Pylance is now newly presenting peculiar type signatures for methods of
TorrentDictionary
objects.For example, this used to be fine with Pylance:
mytorrentdict.recheck()
But now that same line causes Pylance to complain
Argument missing for parameter "self"
and display this type signature:(method) recheck: _Wrapped[(self: TorrentsAPIMixIn, torrent_hashes: Iterable[str] | None = None, **kwargs: APIKwargsT), None, (self: TorrentDictionary, **kwargs: APIKwargsT), None]
This occurs for many (if not all)
TorrentDictionary
methods.Steps to reproduce
Try
mytorrentdict.recheck()
in code edited within Visual Studio 1.91.0 with Pylance installed.Expected behavior
Pylance should not complain about
mytorrentdict.recheck()
, and the type signature should not includeself
as the first parameter.Screenshots
No response
Environment
Additional context
While it is possible that this is somehow the fault of Pylance, I tend to look to qbittorrent-api, as the only thing altered in my environment was a qbittorrent-api update, after which Pylance identified dozens of "errors" in mature code that certainly continues to work properly.
Also, Pylance has no complaint about use of client methods such as
client.torrents_recheck()
, but I'd prefer not to overhaul the code to use those forms unless absolutely necessary.