Skip to content

Conversation

@EvgenyVashkevich
Copy link

(Explain how this PR changes mypy.)

@brianschubert
Copy link
Member

Thanks for the PR! However, it looks a primitive for bytes.decode already exists:

# obj.decode()
method_op(
name="decode",
arg_types=[bytes_rprimitive],
return_type=str_rprimitive,
c_function_name="CPy_Decode",
error_kind=ERR_MAGIC,
extra_int_constants=[(0, pointer_rprimitive), (0, pointer_rprimitive)],
)
# obj.decode(encoding)
method_op(
name="decode",
arg_types=[bytes_rprimitive, str_rprimitive],
return_type=str_rprimitive,
c_function_name="CPy_Decode",
error_kind=ERR_MAGIC,
extra_int_constants=[(0, pointer_rprimitive)],
)
# obj.decode(encoding, errors)
method_op(
name="decode",
arg_types=[bytes_rprimitive, str_rprimitive, str_rprimitive],
return_type=str_rprimitive,
c_function_name="CPy_Decode",
error_kind=ERR_MAGIC,
)

@hauntsaninja hauntsaninja added the pending Issues that may be closed label Apr 17, 2025
Copy link
Collaborator

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

As already stated above mypy already has this implemented! For .decode(encoding) too, not just assuming encoding == "utf-8".


[case testDecodeUtf8]
def f(b: bytes) -> str:
return b.decode("utf-8")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well it's silly to have a parameter when we only support "utf-8". It doesn't look like you have a fallback either but I don't really know mypyc.

@A5rocks A5rocks closed this Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending Issues that may be closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants