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

Add stubs for uic #150

Open
AranaFireheartSNHU opened this issue Apr 7, 2021 · 2 comments
Open

Add stubs for uic #150

AranaFireheartSNHU opened this issue Apr 7, 2021 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@AranaFireheartSNHU
Copy link

Steps

Install PyQt5 package and type the import statement:
from PyQt5 import QtGui, uic
PyCharm will offer to install PyQt5-stubs. Agree.
Actual - uic submodule is marked as unresolved. The code runs.

Reported to JetBrains, and listed as an issue:
https://youtrack.jetbrains.com/issue/PY-47685

@BryceBeagle
Copy link
Collaborator

Looks like we're missing the uic.pyi stub file. Not sure if it's being generated and not properly kept, or if it's not being generated at all.

@BryceBeagle BryceBeagle added the bug Something isn't working label Apr 7, 2021
@bluebird75 bluebird75 added enhancement New feature or request and removed bug Something isn't working labels Jan 4, 2022
@bluebird75 bluebird75 changed the title PyQt5-stubs breaks code insight PyCharm Add stubs for uic Jan 4, 2022
@bluebird75 bluebird75 added the good first issue Good for newcomers label Jan 4, 2022
@1j01
Copy link

1j01 commented Oct 19, 2023

As a workaround, I added this to my app's code:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    # PyQt5-stubs doesn't include the uic module
    # https://github.com/python-qt-tools/PyQt5-stubs/issues/150
    # I tried adding a stub for it, but then QtCore couldn't be resolved,
    # so it seems stubs can't overlap with other stub packages.
    # This is a simple workaround, and I could probably move it to a .pyi module,
    # and just add a different import here instead of defining a class as a stand-in for a module.
    class uic:
        @staticmethod
        def loadUi(uifile: str, baseinstance: QWidget|None = None, package: str = "", resource_suffix: str = "_rc") -> QWidget:
            """loadUi(uifile, baseinstance=None, package='') -> widget

            Load a Qt Designer .ui file and return an instance of the user interface.

            uifile is a file name or file-like object containing the .ui file.
            baseinstance is an optional instance of the Qt base class.  If specified
            then the user interface is created in it.  Otherwise a new instance of the
            base class is automatically created.
            package is the optional package which is used as the base for any relative
            imports of custom widgets.
            resource_suffix is the suffix appended to the basename of any resource file
            specified in the .ui file to create the name of the Python module generated
            from the resource file by pyrcc4.  The default is '_rc', i.e. if the .ui
            file specified a resource file called foo.qrc then the corresponding Python
            module is foo_rc.
            """
            ...

I'm no longer using PyQt5-stubs as I've upgraded to PyQt6, but this could be used as a headstart if someone wants to add this to the type stubs properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants