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

Strange new type signature issues for TorrentDictionary methods #471

Closed
bland328 opened this issue Jul 8, 2024 · 6 comments · Fixed by #472
Closed

Strange new type signature issues for TorrentDictionary methods #471

bland328 opened this issue Jul 8, 2024 · 6 comments · Fixed by #472
Labels
bug Something isn't working

Comments

@bland328
Copy link

bland328 commented Jul 8, 2024

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 include self as the first parameter.

Screenshots

No response

Environment

  • Operating System: macOS
  • Python version: 3.12
  • Software versions:
    • qBittorrent: v4.6.5
    • qbittorrent-api: 2024.5.63

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.

@bland328 bland328 added the bug Something isn't working label Jul 8, 2024
@rmartin16
Copy link
Owner

Hmm....thanks for letting me know. I've had similar issues recently with mypy (see #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...

@bland328
Copy link
Author

bland328 commented Jul 8, 2024

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.

@bland328
Copy link
Author

bland328 commented Jul 8, 2024

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.

@rmartin16
Copy link
Owner

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...

@rmartin16
Copy link
Owner

@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

@rmartin16
Copy link
Owner

v2024.7.64 is now published with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants