Skip to content

Enable mypy option --disallow-any-generics - #2459

Closed
michaeloliverx wants to merge 10 commits into
encode:masterfrom
michaeloliverx:mypy-disallow-any-generics
Closed

michaeloliverx wants to merge 10 commits into
encode:masterfrom
michaeloliverx:mypy-disallow-any-generics

Conversation

@michaeloliverx

Copy link
Copy Markdown
Contributor

Refs #2436

@michaeloliverx
michaeloliverx marked this pull request as ready for review November 22, 2022 10:01
@michaeloliverx
michaeloliverx requested review from lovelydinosaur and removed request for lovelydinosaur November 22, 2022 10:01
Comment thread httpx/_auth.py Resolved
Comment thread httpx/_transports/wsgi.py Outdated

if typing.TYPE_CHECKING:
from _typeshed import OptExcInfo # pragma: no cover
from _typeshed.wsgi import WSGIApplication # pragma: no cover

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you talk me through these? It's confusing to me that _typeshed is named as a private module. Should we be replicating the definitions rather than importing them?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The _typeshed package and its types do not exist at runtime, but can be used freely in stubs (.pyi) files. To import the types from this package in implementation (.py) files, use the following construct:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from _typeshed import ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are utility types used by the typeshed, I see no advantage in replicating them ourselves as mypy and pyright both ship with a recent copy of typeshed. These are strictly used for type checking and have no runtime implications.

Read more at https://github.com/python/typeshed/tree/main/stdlib/_typeshed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These particular types exist in python 3.11 under wsgiref.types so eventually we can remove them.

@michaeloliverx

Copy link
Copy Markdown
Contributor Author

@tomchristie sorry I was out for a bit, this should be good to go now.

@lovelydinosaur

Copy link
Copy Markdown
Member

Okay thanks, few more conflicts here.

@michaeloliverx

Copy link
Copy Markdown
Contributor Author

This has been covered by #2468

@michaeloliverx
michaeloliverx deleted the mypy-disallow-any-generics branch November 29, 2022 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants