Skip to content

Commit ff716fa

Browse files
committed
Improve TypeVarId comments
1 parent ffd3957 commit ff716fa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mypy/types.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@ def deserialize(cls, data: JsonDict) -> 'Type':
4848

4949

5050
class TypeVarId:
51-
# 1, 2, ... for type-related, -1, ... for function-related
51+
# A type variable is uniquely identified by its raw id and meta level.
52+
53+
# For plain variables (type parameters of generic classes and
54+
# functions) raw ids are allocated by semantic analysis, using
55+
# positive ids 1, 2, ... for generic class parameters and negative
56+
# ids -1, ... for generic function type arguments. This convention
57+
# is only used to keep type variable ids distinct when allocating
58+
# them; the type checker makes no distinction between class and
59+
# function type variables.
60+
61+
# Metavariables are allocated unique ids starting from 1.
5262
raw_id = 0 # type: int
5363

5464
# Level of the variable in type inference. Currently either 0 for
55-
# declared types, or 1 for type inference unification variables.
65+
# declared types, or 1 for type inference metavariables.
5666
meta_level = 0 # type: int
5767

58-
# Used for allocating fresh ids
68+
# Class variable used for allocating fresh ids for metavariables.
5969
next_raw_id = 1 # type: int
6070

6171
def __init__(self, raw_id: int, meta_level: int = 0) -> None:

0 commit comments

Comments
 (0)