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

Cannot manage to make the stubs used by PyCharm. #2

Open
MrLixm opened this issue May 2, 2023 · 4 comments
Open

Cannot manage to make the stubs used by PyCharm. #2

MrLixm opened this issue May 2, 2023 · 4 comments

Comments

@MrLixm
Copy link

MrLixm commented May 2, 2023

Hello, I have been trying to get your stubs working alongside my PyCharm project.

I am using Qt.py from which types-PySide is perfectly installed using 1.3.8. But they are not being picked by PyCharm at all.

The reasons for now are :

  • PyCharm create some pre-build "binary skeletons", I need to remove them from External Libraries/Binary Skeletons.
  • Then it seems PySide2 comes with its own stubs file installed along. You can just perform a pip install PySide2 --target "somedir/", look at the content of somedir and notice a .pyi file for each root Qt module. Again I can deleted those manually but though it's not a good practice as this need to be performed at each venv update.

Here is a screenshot of the site-packages directory of the venv :

image

So this would actually be more of a "discussion" than an "issue" as there is no issue with types-PySide directly, just PyCharm being annoying to work with. I'm still creating the issue so it can maybe help other people having the same issue.

I'm looking for any advice on the resolution that would involve minimal hackery.

  • Is there any flag when installing PySide2 so it doesn't install stubs
  • Can I make PySide2-stubs stubs take priority over the .pyi files in PySide2 directory ?
Context

PyCharm 2022.3.2
Poetry 1.2.0
Qt.py 1.3.8
types-PySide2 5.15.2.1.5

Feel free to close this if you don't estimate it's the right place to discuss it.
Cheers.
Liam.

@chadrik
Copy link
Owner

chadrik commented May 3, 2023

Hmmm... you're right. I deleted the .pyi stubs from PySide2 and then PyCharm just started using its own cached stubs. I could only get PyCharm to use PySide2-stubs if I uninstalled PySide2.

I found this issue that was made for a similar problem, but there was no resolution. This problem may be specific to compiled modules (.dll, .so).

One possible solution is to distribute these as stubs for Qt.py instead of (or in addition to) PySide2. You can test this yourself by deleting Qt-stubs directory from your venv and renaming PySide2-stubs to Qt-stubs. After making this switch I get proper inspection in PyCharm for Qt modules.

@MrLixm
Copy link
Author

MrLixm commented May 3, 2023

Thanks your suggested workaround looks the way to go.
Though I'm still wondering what would be the solution if I did not used Qt.py.
Where are those PySide2 pre-generated pyi files coming from ?

@chadrik
Copy link
Owner

chadrik commented May 3, 2023

I'm trying to understand that as well.

In PyCharm there are 3 layers of stubs for PySide2:

  1. the pyi files that are distributed with PySide2 itself and get installed when you pip install PySide2 (they are not very accurate)
  2. the stubs dynamically created by PyCharm from the PySide2 .so files
  3. the pyi files from types-pyside that get installed to PySide2-stubs

As far as PyCharm is concerned the order of precedence seems to be the order that I've listed above. It uses the .pyi files in PySide2, but when I delete them it uses its own stubs that it generates from inspecting PySide, and only after removing PySide2 from the venv does PyCharm look at the pyi files in PySide2-stubs.

The other question is what does PEP 561 say about the order of precedence between stubs within a package (PySide2) and stubs within a stubs-only package (PySide2-stubs)? In other words, what is the correct behavior that should be implemented by IDEs like mypy and type checkers like mypy? A quick skim suggests this may not be well defined.

I'm going to leave this open until I have something better than what we have now, probably something with providing Qt-stubs.

@MrLixm
Copy link
Author

MrLixm commented May 3, 2023

A quick skim suggests this may not be well defined.

Even though it was defined and for example PySide2 pyi distributed file should takes over, we would be still stuck.
Until we find a way to install PySide2 without any builtin stubs.

Else here is my current solution for my project, that work with poetry. That way anyone can just rebuild the venv on his side.

2023_05_03_192502_1508x821

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

No branches or pull requests

2 participants