Skip to content

Follow PEP 8 recommendations for type variable names #1872

Closed
@ilevkivskyi

Description

@ilevkivskyi

This appeared in #1856

The problem is that type variable names in some stubs don't follow PEP 8 that recommends short names. This recommendation exists for a reason: behaviour of some constructs is subtly different with type variables and normal types, so it should be immediately clear that a given name refers to a type variable. Most notable examples are generic base classes and generic type aliases, where this leads to false negatives (unless --disallow-any-generics is used):

LongNameLikeAClass = TypeVar('LongNameLikeAClass')
# 300 lines later
class Cls(Iterable[LongNameLikeAClass]):  # it's not obvious this class is generic
    ...
Alias = Dict[str, List[LongNameLikeAClass]]  # even more here, this looks like a normal alias

def fun(arg: Cls) -> Alias:  # two `Any`s sneaked in here
    ...

(it is not something hypothetic, I have seen this kind of errors many times)

I propose to replace the existing long type variable names to follow PEP 8 style. If someone really doesn't like short names, we could propose some other agreement, like end long type variable names with _TVar.

Metadata

Metadata

Assignees

Labels

stubs: improvementImprove/refactor existing annotations, other stubs issues

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions