-
Notifications
You must be signed in to change notification settings - Fork 175
Feat/fix return type for mux #738
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
Conversation
Feat/fix return type for mux for libp2p#736
Feat/fix multiselect type consistency
…/fix-return-type-for-mux
@Aldorax and @manny-uncharted : Welcome to py-libp2p :) Thank you for submitting this PR. Appreciate your efforts and initiative. CCing @acul71 , @sumanjeet0012 for their feedback and review on return type for mux. Also, CCing @Khwahish29 and @mystical-prog , who are working together on abc.py interfaces and anyio upgrades too. |
I will surely look into this! Appreciate the heads up! |
Closing this PR as shared by the author at #742 (comment) . |
Fix: Correct
get_mux()
return type and module ordering for #736What was wrong?
The
IHost.get_mux()
abstract method inlibp2p/abc.py
incorrectly usedAny
as its return type. An attempt to specify the preciseIMultiselectMuxer
type led to an "Undefined name" error from static analysis tools. This was caused byIMultiselectMuxer
being defined afterIHost
in thelibp2p/abc.py
file, creating a forward-reference issue during parsing.Additionally, type annotations and imports in the
BasicHost
implementation (libp2p/host/basic_host.py
) and inlibp2p/protocol_muxer/multiselect.py
were not fully aligned with the correctIMultiselectMuxer
type.How was it fixed?
The issue was resolved through the following steps:
libp2p/abc.py
: The definitions ofIMultiselectCommunicator
,IMultiselectClient
, andIMultiselectMuxer
were strategically moved to appear before theIHost
class definition withinlibp2p/abc.py
. This ensures proper symbol resolution during parsing.IHost.get_mux()
inlibp2p/abc.py
was accurately updated fromAny
toIMultiselectMuxer
, bringing the interface definition into alignment.BasicHost.get_mux()
inlibp2p/host/basic_host.py
was also updated toIMultiselectMuxer
to match the corrected interface.libp2p/host/basic_host.py
was updated to correctly importIMultiselectMuxer
fromlibp2p.abc
.libp2p/protocol_muxer/multiselect.py
was updated to importIMultiselectCommunicator
andIMultiselectMuxer
directly fromlibp2p.abc
to reflect the consolidated interface definitions.These changes significantly enhance the type safety and clarity of the API for static analysis tools like Pyrefly, providing more robust code verification.
To-Do
IHost.get_mux()
)bugfix
orinternal
)Cute Animal Picture