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

[mypyc] Add bytes primitive type #9611

Closed
wants to merge 10 commits into from
Closed

[mypyc] Add bytes primitive type #9611

wants to merge 10 commits into from

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Oct 18, 2020

This adds minimal support for the bytes primitive type. This won't
improve performance until we implement some more primitives.
Actually, this will likely degrade performance a bit, since we now add
type checks for bytes values.

Unfortunately, most of the bytes operations we'd need are private in
CPython, so we'll need to either depend on implementation details or
reimplement (or copy+paste) a bunch of code.

Work on mypyc/mypyc#644.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Oct 25, 2020

There were various test failures because of a bad annotation in typed_ast stubs. It should be fixed now.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Oct 27, 2020

Now we have a problem with group(n) of regular expression objects potentially returning None, but the return type is non-optional in typeshed. I can come up with a workaround here, but we should really have a general fix.

We could fix typeshed -- maybe the return type should be Union[bytes, Any] instead of bytes? In that case mypyc would do the right thing.

In any case these issues are very useful findings. Mypyc is a good at finding typeshed bugs!

@hauntsaninja
Copy link
Collaborator

The match group thing keeps coming up, I'm in favour of a Union Any return (with maybe some overloads for when we don't need it): python/typeshed#3902 (comment)

@TH3CHARLie
Copy link
Collaborator

What's the status quo of the match group thing? Is it still a blocker of this?

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 15, 2021

I think that it's still an issue. I kind of forgot about this PR. The typeshed fix should be fairly straightforward (but it needs to be synced back to mypy).

@JelleZijlstra
Copy link
Member

group was already changed to return AnyStr | Any: https://github.com/python/typeshed/blob/master/stdlib/typing.pyi#L568

@97littleleaf11
Copy link
Collaborator

Hi! @hauntsaninja, I'm working on bytes primitives, shall we sync the typeshed to fix current match.group issue?

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jul 24, 2021

Sure, I opened #10862

97littleleaf11 added a commit to 97littleleaf11/mypy that referenced this pull request Jul 26, 2021
JukkaL pushed a commit that referenced this pull request Jul 28, 2021
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 30, 2021

Closing in favor of #10881.

@JukkaL JukkaL closed this Jul 30, 2021
@97littleleaf11 97littleleaf11 deleted the mypyc-bytes branch March 25, 2022 10:24
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.

6 participants