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

Slots can return any object #57

Merged
merged 1 commit into from
Sep 13, 2020
Merged

Conversation

altendky
Copy link
Collaborator

There is no requirement that slots return specifically None, any object will do.

There is no requirement that slots return specifically `None`, any `object` will do.
@BryceBeagle
Copy link
Collaborator

Can this not be Callable[..., Any] or even just plain Callable?

@altendky
Copy link
Collaborator Author

Any means that you can do anything you want with the value which isn't a good default since you don't know what it will be. object means it can be any object and you can only expect to do things to it that you can do with object, which is mostly the case (pending objects that block access to object features).

In this case it probably doesn't make much difference, but object is a more sensible default as it doesn't effectively disable type hints. Bare typing.Callable just defaults to the Any.

@altendky altendky mentioned this pull request Sep 13, 2020
15 tasks
@stlehmann stlehmann merged commit 50f45f5 into python-qt-tools:master Sep 13, 2020
@The-Compiler
Copy link
Collaborator

I'm not really convinced object (over Any) is the right thing to do here - that being said, I've never used slot return values. But surely you'd usually know what type you get from a specific slot and then do things based on that type? If you get object back, like you say, you pretty much can't do anything with the return value, no?

@altendky
Copy link
Collaborator Author

object forces you, the only person that has any basis for knowing, to explicitly state that you know via a typing.cast(). Any leaves you ignorantly passing type hint checks even if you erroneously use the result as if it is two different types.

But does this hint leak back out to anything outside? My impression was that it just describes what sorts of things are accepted in various places that need a slot. I think the next layer is to get into Generics so that we can actually relate the type of the incoming callable and properly hint the outputs. But I haven't even started to think about where or how that would look. I expect that to be a tough task.

@altendky altendky deleted the patch-3 branch September 13, 2020 18:40
bluebird75 pushed a commit to bluebird75/PyQt5-stubs that referenced this pull request Aug 24, 2021
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.

4 participants