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

email.message: Fix invalid TypeVar usage; add some default values #9620

Merged
merged 1 commit into from Jan 30, 2023

Conversation

AlexWaygood
Copy link
Member

Refs #9608. For all of the functions touched here, the _T TypeVar would go unsolved if no value was passed by the user for the failobj parameter. We have to use overloads here to ensure that _T will never silently be resolved as Any

@github-actions
Copy link
Contributor

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

pip (https://github.com/pypa/pip)
+ src/pip/_internal/metadata/_json.py:67: error: Item "None" of "Optional[List[Any]]" has no attribute "__iter__" (not iterable)  [union-attr]
+ src/pip/_internal/metadata/_json.py:70: error: Argument 1 to "sanitise_header" has incompatible type "Optional[Any]"; expected "Union[Header, str]"  [arg-type]

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/helpers.py:749: error: Value of type "Optional[List[Tuple[str, str]]]" is not indexable  [index]

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Jan 30, 2023

Links to the primer hits:

https://github.com/pypa/pip/blob/e3e7bc34eb486622ebbb6412afc98ee57fcbff4a/src/pip/_internal/metadata/_json.py#L67-L70

https://github.com/aio-libs/aiohttp/blob/4635161ee8e7ad321cca46e01ce5bfeb1ad8bf26/aiohttp/helpers.py#L748-L749

These are both true positives, in my opinion: these are both cases where _T was previously being silently resolved to Any by mypy, meaning that it didn't notice the typing errors in the user code.

@srittau srittau merged commit b5a26d1 into python:main Jan 30, 2023
@AlexWaygood AlexWaygood deleted the email-overloads branch January 30, 2023 16:56
@srittau
Copy link
Collaborator

srittau commented Jan 30, 2023

This would a good case for type var defaults (python/typing#307) as well.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Mar 21, 2023
…2924

https://build.opensuse.org/request/show/1072924
by user dirkmueller + dimstar_suse
- update to 6.1.0:
  * ``packages_distributions`` now honors packages and
    modules with Python modules that not ``.py`` sources (e.g.
    ``.pyc``, *   ``.so``).
  * #434: Expand protocol for ``PackageMetadata.get_all`` to
    match the upstream implementation of ``email.message.Message.get_all``
    in python/typeshed#9620.
kraj pushed a commit to YoeDistro/poky that referenced this pull request Apr 10, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

(From OE-Core rev: 8cb0c21f597e4486229a7b42e00d3a681622ad9d)

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
kraj pushed a commit to YoeDistro/poky that referenced this pull request Apr 11, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

(From OE-Core rev: 1aac50ba9b58866a91fb64c0408c4b0425ad1f75)

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
kraj pushed a commit to YoeDistro/poky that referenced this pull request Apr 11, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

(From OE-Core rev: c718e376fa8453f1998416c3c22139711cd6ff56)

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
kraj pushed a commit to YoeDistro/poky that referenced this pull request Apr 11, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

(From OE-Core rev: c718e376fa8453f1998416c3c22139711cd6ff56)

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
kraj pushed a commit to YoeDistro/poky that referenced this pull request Apr 12, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

(From OE-Core rev: fde9a92e05c0b01304fa40dba743f9c7b32c628f)

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
kraj pushed a commit to YoeDistro/poky that referenced this pull request Apr 12, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

(From OE-Core rev: fde9a92e05c0b01304fa40dba743f9c7b32c628f)

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
rpurdie pushed a commit to yoctoproject/poky that referenced this pull request Apr 13, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

(From OE-Core rev: e3991141939e5e2393cf36edd02ef3765cacd330)

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to openembedded/openembedded-core that referenced this pull request Apr 13, 2023
Changelog:
===========
- #384: PackageMetadata now stipulates an additional get method allowing for
  easy querying of metadata keys that may not be present.
- #428: packages_distributions now honors packages and modules with Python
  modules that not .py sources (e.g. .pyc, .so).
- #434: Expand protocol for PackageMetadata.get_all to match the upstream
  implementation of email.message.Message.get_all in python/typeshed#9620.

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
hauntsaninja added a commit to hauntsaninja/pip that referenced this pull request Sep 23, 2023
Mostly straightforward.

The new message.get_all type ignores out of fear it may return None are
minorly annoying. You can see some of the extra errors on the pip
codebase in the mypy_primer of the typeshed PR that made the change
python/typeshed#9620

The abstract errors are because FakeDistribution doesn't actually
implement any of the Protocol it claims to implement
hauntsaninja added a commit to hauntsaninja/pip that referenced this pull request Sep 23, 2023
Mostly straightforward.

The new message.get_all type ignores out of fear it may return None are
minorly annoying. You can see some of the extra errors on the pip
codebase in the mypy_primer of the typeshed PR that made the change
python/typeshed#9620

The abstract errors are because FakeDistribution doesn't actually
implement any of the Protocol it claims to implement
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.

None yet

2 participants