Skip to content

Use of twisted in pika #9494

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

Merged
merged 14 commits into from
Mar 25, 2023
Merged

Use of twisted in pika #9494

merged 14 commits into from
Mar 25, 2023

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Jan 11, 2023

Fixes 2 Any subclassing issues

This would require the stub_uploader to allow twisted
The twisted types have been replicated.

I've completed as many things referencing twisted as I could find.

Ref: #9491

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

I don't think there's enough of a win here for this to be worth it. twisted is just an optional backend for pika; if somebody decides to use tornado as a backend instead, then the extra dependency is pointless. And even if they do use twisted, the twisted types still don't seem fundamental to the package, really.

Just because we can have non-types dependencies now doesn't mean we should add them everywhere. We should still strive for stubs packages to have minimal dependencies, and present minimal security risks, wherever possible.

@Avasam
Copy link
Collaborator Author

Avasam commented Jan 11, 2023

So it's an optional dependency just like Qt is to Pillow.

I don't think there's enough of a win here for this to be worth it.
[…] the twisted types still don't seem fundamental to the package, really

So would Any subclassing be acceptable here?
Or if its not too complex, I can look into replicating the base class(es) is the stub.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jan 11, 2023

So would Any subclassing be acceptable here?
Or if its not too complex, I can look into replicating the base class(es) is the stub.

Any subclassing is never good exactly, so if you'd like to try mimicking the shape using protocols or whatever, sure 😀

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@github-actions

This comment has been minimized.

@Avasam Avasam requested a review from AlexWaygood January 14, 2023 02:13
@Avasam Avasam mentioned this pull request Feb 1, 2023
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member

I appreciate the work here but I'm wary of adding so much code that we can't validate with stubtest or other automatic tools.

It might make sense to import the types from Twisted without declaring an explicit dependency on Twisted for the stubs package. Users who use the Twisted backend presumably will also have Twisted installed in their venv, so they will get precise types. If they don't, type checkers will just fall back to Any.

@Avasam
Copy link
Collaborator Author

Avasam commented Mar 22, 2023

It might make sense to import the types from Twisted without declaring an explicit dependency on Twisted for the stubs package.

That's something I've suggested a few times for different stubs with similar issues. (the idea of "optional" or "test only" dependencies). The issue with the current setup is that we can do that for stubtest, but not for every other tests like mypy, pyright, pytype, flake8, ... Especially with Pyright you can end up with unknowns that bubble up and you have to # pyright: ignore a bunch of stuff.

I'll see what I can do for Twisted in Pika, it's been a while I haven't touched this PR.

@Avasam
Copy link
Collaborator Author

Avasam commented Mar 22, 2023

Alright, this is what it looks like in pika. Not too bad given that usage of twisted is restricted to the twisted_connection module.
I guess it technically solves subclassing Any? Even though mypy will still report it because the package is missing in test.
The same could be done for tornado_connection and gevent_connection.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

It's not exactly pretty, but I'm on board with this new approach!

@JelleZijlstra JelleZijlstra merged commit 2e59b81 into python:main Mar 25, 2023
@Avasam Avasam deleted the twisted-in-pika branch March 25, 2023 05:00
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.

3 participants