Skip to content

[mypyc] Add bytes primitive type - #10881

Merged
JukkaL merged 7 commits into
python:masterfrom
97littleleaf11:add-bytes
Jul 28, 2021
Merged

JukkaL merged 7 commits into
python:masterfrom
97littleleaf11:add-bytes

Conversation

@97littleleaf11

@97littleleaf11 97littleleaf11 commented Jul 26, 2021 •

Copy link
Copy Markdown
Collaborator

Description

Replaces #9611

Test Plan

#9611 encountered several test failures and this PR fixes them on latest branch.

@97littleleaf11 97littleleaf11 changed the title [mypyc] Add bytes primitive [mypyc] Add bytes primitive type Jul 26, 2021
@97littleleaf11

Copy link
Copy Markdown
Collaborator Author

I manually sync python/typeshed#5557 to see whether we could pass all tests temporally.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

werkzeug (https://github.com/pallets/werkzeug.git)
+ src/werkzeug/http.py:456: error: Unsupported operand types for + ("str" and "None")
+ src/werkzeug/http.py:456: note: Right operand is of type "Optional[str]"
+ src/werkzeug/http.py:458: error: Incompatible types in assignment (expression has type "Optional[str]", target has type "str")
- tests/test_wrappers.py:840: error: Function is missing a return type annotation
- tests/test_wrappers.py:840: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:852: error: Function is missing a return type annotation
- tests/test_wrappers.py:852: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ tests/test_wrappers.py:840: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)

pydantic (https://github.com/samuelcolvin/pydantic.git)
+ pydantic/networks.py:267: error: Item "None" of "Optional[Match[str]]" has no attribute "group"  [union-attr]

sphinx (https://github.com/sphinx-doc/sphinx.git)
+ sphinx/ext/autodoc/__init__.py: note: In member "parse_name" of class "Documenter":
+ sphinx/ext/autodoc/__init__.py:408:23: error: Need type annotation for "parents"

aiohttp (https://github.com/aio-libs/aiohttp.git)
+ aiohttp/client_reqrep.py:809: error: unused "type: ignore" comment
+ aiohttp/client_reqrep.py:813: error: Argument 1 to "add" of "MultiDict" has incompatible type "Union[str, Any, URL]"; expected "Union[str, istr]"  [arg-type]

JukkaL added a commit that referenced this pull request Jul 28, 2021
When trying to match `list[T]` and `list[str] | Any`, previously we
gave up, because the union items caused conflicting inferred values
for `T` (`str` and `Any`). Work around the issue by dropping `Any`
constraints if there are multiple sets of contraints, since we
prefer more precise types.

This fixes false positives resulting from python/typeshed#5557,
which changed some return types to contain unions with `Any` items.
See mypy primer results in #10881 for a real-world example of this
in sphinx.

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me!

@JukkaL
JukkaL merged commit 10dc451 into python:master Jul 28, 2021
@JukkaL

JukkaL commented Jul 28, 2021

Copy link
Copy Markdown
Collaborator

#10887 fixes the false positive in sphinx (from mypy_primer). The other new errors look real.

JukkaL added a commit that referenced this pull request Jul 28, 2021
)

When trying to match `list[T]` and `list[str] | Any`, previously we
gave up, because the union items caused conflicting inferred values
for `T` (`str` and `Any`). Work around the issue by dropping `Any`
constraints if there are multiple sets of contraints, since we
prefer more precise types.

This fixes false positives resulting from python/typeshed#5557,
which changed some return types to contain unions with `Any` items.
See mypy primer results in #10881 for a real-world example of this
in sphinx.
@97littleleaf11
97littleleaf11 deleted the add-bytes branch July 30, 2021 09:44
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.

2 participants