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

Please add support for indexing pyqtSignal Objects. #9

Closed
deavid opened this issue Jul 31, 2019 · 6 comments
Closed

Please add support for indexing pyqtSignal Objects. #9

deavid opened this issue Jul 31, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@deavid
Copy link

deavid commented Jul 31, 2019

https://github.com/stlehmann/PyQt5-stubs/blob/189a0497d08ddd65f46e4819f427eb2d03196589/PyQt5-stubs/QtCore.pyi#L31

See this link:
https://stackoverflow.com/questions/45337136/qsignalmapper-in-pyqt5-not-working-when-the-function-argument-is-a-str

We're expected to do: "mapper.mapped[str].connect(a_function)" in order to retrieve the overload we want for the signal.

It should be enough if we add getitem returning pyqtSignal.

@deavid deavid changed the title Please add support for indexing Please add support for indexing pyqtSignal Objects. Jul 31, 2019
@BryceBeagle
Copy link
Collaborator

Was this implemented? I still see pyqtSignals as not indexable

class CoolClass(QObject):
    signal = pyqtSignal([int], [str])

    def __init__(self) -> None:
        super().__init__()
        self.signal[int].connect(lambda val: print(val))
        self.signal[str].connect(lambda val: print(val[::-1]))


instance = CoolClass()
instance.signal[int].emit(5)
instance.signal[str].emit("five")
tests/pyqtslot.py:16: error: Value of type "pyqtSignal" is not indexable
tests/pyqtslot.py:17: error: Value of type "pyqtSignal" is not indexable
tests/pyqtslot.py:21: error: Value of type "pyqtSignal" is not indexable
tests/pyqtslot.py:22: error: Value of type "pyqtSignal" is not indexable
Found 4 errors in 1 file (checked 1 source file)


tests/test_stubs.py:14 (test_stubs[pyqtslot.py])
filename = 'pyqtslot.py'

    @pytest.mark.parametrize('filename', list(gen_tests()))
    def test_stubs(filename):
        """Run mypy over example files."""
        path = os.path.join(TESTS_DIR, filename)
        stdout, stderr, exitcode = api.run([path])
        if stdout:
            print(stdout)
    
>       assert stdout.startswith("Success: no issues found")
E       assert False
E        +  where False = <built-in method startswith of str object at 0x7f7d90cffcb0>('Success: no issues found')
E        +    where <built-in method startswith of str object at 0x7f7d90cffcb0> = 'tests/pyqtslot.py:16: error: Value of type "pyqtSignal" is not indexable\ntests/pyqtslot.py:17: error: Value of type ...pyqtslot.py:22: error: Value of type "pyqtSignal" is not indexable\nFound 4 errors in 1 file (checked 1 source file)\n'.startswith

tests/test_stubs.py:23: AssertionError

@stlehmann stlehmann reopened this May 1, 2020
@stlehmann
Copy link
Collaborator

No this has not been implemented, yet. I closed it because it was an old issue. As it is not a feature I am using I must admit that I didn't have a close look at it. But did so now. I think that's definetly a thing we could do.

@stlehmann stlehmann added the enhancement New feature or request label May 1, 2020
@stlehmann
Copy link
Collaborator

@BryceBeagle would you like to take care of it?

@altendky
Copy link
Collaborator

I just added pyqtBoundSignal.__getitem__() as suggest by the OP in the OP to #56. I could be talked into making it a separate follow-up PR if people find the two changes sufficiently unrelated.

@altendky
Copy link
Collaborator

altendky commented Oct 2, 2020

#56 is merged. @deavid, does that look like it does what you wanted? It doesn't implement anything as to the actual types but it should at least let you go through the motions unchecked and without complaint.

@deavid
Copy link
Author

deavid commented Oct 2, 2020

Hi, I moved away from the original project that required this and @Aulla is on it at the moment. Maybe he can comment here. For now, I'll just close this.

@deavid deavid closed this as completed Oct 2, 2020
bluebird75 pushed a commit to bluebird75/PyQt5-stubs that referenced this issue Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants