Skip to content

Use short type var names per PEP 8#4553

Closed
srittau wants to merge 1 commit into
python:masterfrom
srittau:short-type-vars
Closed

Use short type var names per PEP 8#4553
srittau wants to merge 1 commit into
python:masterfrom
srittau:short-type-vars

Conversation

@srittau

@srittau srittau commented Sep 17, 2020

Copy link
Copy Markdown
Collaborator

Closes: #1872

@hauntsaninja hauntsaninja 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.

I personally like the T suffix (#1872 (comment)), but whatever :-)

def __init__(self, min: Optional[int] = ..., max: Optional[int] = ..., clamp: bool = ...) -> None: ...

_PathType = TypeVar("_PathType", str, bytes)
_PathType = Any

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.

Suggested change
_PathType = Any
_PathType = AnyStr

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

_PathType is never used as a type variable, it's just a glorified Union[str, bytes] return type. (Which means I can leave my obligatory link to python/typing#566 here.)

@JelleZijlstra

Copy link
Copy Markdown
Member

This has a couple of merge conflicts now. I'm not sure I like this change; T is fine for a general-purpose typevar, but I find it clearer to use a more explicit name like MessageType for typevars with a bound.

@hauntsaninja

hauntsaninja commented Jan 4, 2021

Copy link
Copy Markdown
Collaborator

It's also bad user experience in the cases where these types get mentioned in type checker error messages (happened recently where we had to rename _LT to _SupportsLessThanT in python/mypy#9582 / #4579).
I opened #4898 as an alternative for the type variables identified in this PR.

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.

Follow PEP 8 recommendations for type variable names

3 participants