Skip to content

[mypyc] Add bytes primitive type - #9611

Closed
JukkaL wants to merge 10 commits into
masterfrom
mypyc-bytes
Closed

JukkaL wants to merge 10 commits into
masterfrom
mypyc-bytes

Conversation

@JukkaL

@JukkaL JukkaL commented Oct 18, 2020 •

Copy link
Copy Markdown
Collaborator

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

JukkaL commented Oct 25, 2020

Copy link
Copy Markdown
Collaborator Author

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

@JukkaL

JukkaL commented Oct 27, 2020

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
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
Copy Markdown
Collaborator

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

@JukkaL

JukkaL commented Jul 15, 2021

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
Member

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

@97littleleaf11

Copy link
Copy Markdown
Collaborator

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

@hauntsaninja

hauntsaninja commented Jul 24, 2021 •

Copy link
Copy Markdown
Collaborator

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

JukkaL commented Jul 30, 2021

Copy link
Copy Markdown
Collaborator Author

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