Skip to content

Conversation

LogicalGuy77
Copy link

What was wrong?

Issue #911 Some methods used generic [Any] type annotations where more specific types could be used, leading to reduced type safety and potential runtime errors. This affected metadata handling in [abc.py] (lines 391, 870, 2135) and [peerstore.py] (line 293), where [Any] was overly permissive for JSON-serializable metadata values.

How was it fixed?

Introduced [MetadataValue] Type Alias:

Added [MetadataValue = Union[str, int, float, bool, list, dict, None]] in [abc.py] to represent JSON-serializable types commonly used for peer metadata.

Updated Method Signatures:

Replaced [Any] with [MetadataValue] in key interfaces and implementations:

  • IPeerMetadata.put() and [get()] in [abc.py]
  • [IPeerStore.put()] and [get()] in [abc.py] and [peerstore.py]
  • IPeerData.put_metadata() and [get_metadata()] in [abc.py]

Fixed Incorrect Return Type:

Corrected IPeerData.get_metadata() to return [MetadataValue] instead of the erroneous IPeerMetadata.

Ensured Consistency:

Updated all related implementations in [peerstore.py] and [peerdata.py] to use the new type, maintaining backward compatibility while improving type safety.

To-Do

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

 /\_/\  
( o.o ) 

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