Skip to content

Fix type annotation inconsistency in negotiate() method #787

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keval215
Copy link

Title: Fix type inconsistency in multiselect negotiate method and add temporary files to gitignore

Description:

Problem
This PR addresses a type inconsistency between the abstract interface and its implementation in the multiselect protocol negotiation:

• The IProtocolMuxer.negotiate() method in libp2p/abc.py has return type Optional[TProtocol] (allowing None)
• The implementation in libp2p/protocol_muxer/multiselect.py had return type TProtocol (not allowing None)
• There was a FIXME comment in the code acknowledging this mismatch

This inconsistency could cause type checking errors and potential runtime issues when the method legitimately returns None during failed negotiations.

Changes Made

  1. Fixed type annotation: Updated the negotiate method's return type in multiselect.py from TProtocol to Optional[TProtocol] to match the abstract interface
  2. Improved gitignore: Added .tmp.driveupload/ pattern to exclude temporary upload files from version control

Benefits
• ✅ Resolves type checking inconsistencies
• ✅ Aligns implementation with abstract interface contract
• ✅ Prevents accidental commits of temporary files
• ✅ Improves code maintainability and type safety

Testing
• Verified type annotations are consistent between interface and implementation
• Confirmed gitignore pattern correctly excludes temporary files
• No functional changes to existing behavior

Checklist
Code changes implemented
Type consistency verified
Gitignore updated

- Update multiselect.py negotiate() return type to match IMultiselectMuxer interface
- Allow TProtocol to be None in return type annotation
- Add .tmp.driveupload/ to .gitignore to exclude temporary upload files

Resolves type inconsistency between abstract interface and concrete implementation.
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.

1 participant