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

(WIP) Update the parameter type annotations for pyqtSignal.__init__ #107

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BryceBeagle
Copy link
Collaborator

@BryceBeagle BryceBeagle commented Oct 8, 2020

Resolves #105

The *types annotation is currently broken. Feedback appreciated

test_stubs.py::test_stubs[pyqtsignal.py]
pyqtsignal.py:6: error: Value of type variable "_SignalTypesT" of "pyqtSignal" cannot be "List[Type[str]]"
pyqtsignal.py:8: error: Value of type variable "_SignalTypesT" of "pyqtSignal" cannot be "object"
Found 2 errors in 1 file (checked 1 source file)

Minimal reprduction of issue:
https://mypy-play.net/?mypy=latest&python=3.8&gist=57db3e86d7202dc8ebe4f24965409a3f

Edit: Opened an issue on the mypy issue tracker: python/mypy#9569

The *types annotation is currently broken. Feedback appreciated
@@ -40,9 +40,22 @@ class pyqtBoundSignal:
@typing.overload
def disconnect(self, slot: typing.Union["PYQT_SLOT", "QMetaObject.Connection"]) -> None: ...


_SignalTypesT = typing.TypeVar("_SignalTypesT", type, typing.List[type])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_SignalTypesT = typing.TypeVar("_SignalTypesT", type, typing.List[type])
_SignalTypesT = typing.TypeVar("_SignalTypesT", typing.Union[type, typing.List[type]])

I can't say I know the reasons for why this works and the separate types don't but... it does. :| Is there something that makes it wrong despite passing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, hold that thought... maybe I didn't test properly here...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, trying again and hoping to be less silly. As is, there is no relationship being created between multiple hints so this can just be an alias instead, I think?

Suggested change
_SignalTypesT = typing.TypeVar("_SignalTypesT", type, typing.List[type])
_SignalTypesT = typing.Union[type, typing.List[type]]

(except with a different variable name changed here and at the use sites)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that I need to keep all of the var args of the same type. Using the Union allows for

a = pyqtSignal([int, bool], float)

but this is not allowed by PyQt. You can use only types OR only lists of types

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think my second attempt was less silly... though still not helpful. Humm.

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

Successfully merging this pull request may close these issues.

pyqtSignal needs the same treatment as pyqtSlot
2 participants