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

Import names from typing directly rather than importing module #13761

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Apr 2, 2025

Import names from typing and typing_extensions directly rather than importing module. (except where aliasing Self as _Self or TypeAlias as _TypeAlias would cause issues for flake8-pyi's Y015 and Y034)
And avoid aliasing said modules.

This was prompted by this comment: #11204 (comment) where I realized we had some inconsistencies.

@@ -2,18 +2,18 @@

import mmap
import re
import typing as t
from typing import AnyStr, Match
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm assuming that importing Match from typing rather than re here is intended for the test.

Comment on lines +219 to +223
[tool.ruff.lint.flake8-import-conventions.aliases]
# Prevent aliasing these, as it causes false-negatives for certain rules
typing_extensions = "typing_extensions"
typing = "typing"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This prevents import typing as t

Comment on lines -8 to +16
def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ...
def convert(self, value: str, param: click.Parameter | None, ctx: click.Context | None) -> str: ...

class PasswordParamType(click.ParamType):
def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ...
def convert(self, value: _T, param: click.Parameter | None, ctx: click.Context | None) -> _T: ...

class TextAreaParamType(click.ParamType):
def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ...
def convert(self, value: _T, param: click.Parameter | None, ctx: click.Context | None) -> _T: ...
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pyhedgehog since you added this stub in #13208
Was there a specific reason to have these as Any?

Copy link
Contributor

github-actions bot commented Apr 2, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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