Make sdp.Server.Service a type alias - #974
Merged
Merged
Conversation
sdp.Server.Service is a NewType over list[ServiceAttribute], and a NewType is
satisfied only by an explicit constructor call. Device.sdp_service_records is
unannotated for that reason: annotating it with the NewType in place causes
mypy errors:
apps/rfcomm_bridge.py:112: error: Dict entry 0 has incompatible type
"int": "list[ServiceAttribute]"; expected "int": "Service"
Make Service a type alias and give Device.sdp_service_records the annotation
the NewType ruled out: sdp_records() helpers are already annotated with
dict[int, list[ServiceAttribute]] by hand.
zxzxwu
approved these changes
Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In my project, I must construct service records by hand and hit the following typing error in the process:
sdp.Server.Serviceis aNewTypeoverlist[ServiceAttribute], and aNewTypeis satisfied only by an explicit constructor call.Device.sdp_service_recordsis unannotated for that reason: annotating it with theNewTypein-place causes mypy errors:I suggest to fix it as follows as the alternative to keep the nominal type and change every producer to return
Server.Servicebreaks every downstream user who assigns a list they built themselves:Make
Servicea type alias and giveDevice.sdp_service_recordsthe annotation theNewTyperuled out:sdp_records()helpers are already annotated withdict[int, list[ServiceAttribute]]by hand.