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

add forward compatibility for byte datagram keys #3045

Merged
merged 1 commit into from
Sep 29, 2020
Merged

Conversation

jackrobison
Copy link
Member

No description provided.

@jackrobison jackrobison added type: improvement Existing (or partially existing) functionality needs to be changed area: DHT labels Sep 14, 2020
@jackrobison jackrobison changed the title and forward compatibility for byte datagram keys add forward compatibility for byte datagram keys Sep 14, 2020
}

if converted[b'0'] in [REQUEST_TYPE, ERROR_TYPE, RESPONSE_TYPE]: # pylint: disable=unsubscriptable-object
datagram_type = converted[b'0'] # pylint: disable=unsubscriptable-object
Copy link
Member

Choose a reason for hiding this comment

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

Does more recent pylint still have this issue? What if you add type information to converted, maybe pylint will detect it as dict then?

@@ -144,27 +144,37 @@ def __init__(self, packet_type: int, rpc_id: bytes, node_id: bytes, exception_ty
self.response = response.decode()


def decode_datagram(datagram: bytes) -> typing.Union[RequestDatagram, ResponseDatagram, ErrorDatagram]:
def _decode_datagram(datagram: bytes):
Copy link
Member

Choose a reason for hiding this comment

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

you lost return type here

Copy link
Member

Choose a reason for hiding this comment

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

i assume that since @jackrobison made this an internal helper function (with underscore) it didn't benefit from having the type info? i think either way is fine: having it doesn't hurt anything, not having it is probably okay in this special case

personally, my preference would be to avoid having such large type Union in the first place, if all of the types have the same parent class, perhaps just say it returns the parent class type? unions should be used as last resort (or when the values returned are truely different, like a function returning an int and a str, in this case it seems it returns Datagrams)

@eukreign eukreign merged commit 318cc15 into master Sep 29, 2020
@eukreign eukreign deleted the bencode-byte-keys branch September 29, 2020 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DHT type: improvement Existing (or partially existing) functionality needs to be changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants