Skip to content

Commit d3fe55a

Browse files
Add comments for can_be_true and can_be_false. Delete redundant slots definition. (#11327)
Adds comments for can_be_true and can_be_false. Deletes redundant redefinition of __slots__.
1 parent 4c6dd24 commit d3fe55a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

mypy/types.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ class Type(mypy.nodes.Context):
130130
"""Abstract base class for all types."""
131131

132132
__slots__ = ('can_be_true', 'can_be_false')
133+
# 'can_be_true' and 'can_be_false' mean whether the value of the
134+
# expression can be true or false in a boolean context. They are useful
135+
# when inferring the type of logic expressions like `x and y`.
136+
#
137+
# For example:
138+
# * the literal `False` can't be true while `True` can.
139+
# * a value with type `bool` can be true or false.
140+
# * `None` can't be true
141+
# * ...
133142

134143
def __init__(self, line: int = -1, column: int = -1) -> None:
135144
super().__init__(line, column)
@@ -1373,8 +1382,7 @@ class TupleType(ProperType):
13731382
implicit: If True, derived from a tuple expression (t,....) instead of Tuple[t, ...]
13741383
"""
13751384

1376-
__slots__ = ('items', 'partial_fallback', 'implicit',
1377-
'can_be_true', 'can_be_false')
1385+
__slots__ = ('items', 'partial_fallback', 'implicit')
13781386

13791387
items: List[Type]
13801388
partial_fallback: Instance
@@ -1451,8 +1459,7 @@ class TypedDictType(ProperType):
14511459
TODO: The fallback structure is perhaps overly complicated.
14521460
"""
14531461

1454-
__slots__ = ('items', 'required_keys', 'fallback',
1455-
'can_be_true', 'can_be_false')
1462+
__slots__ = ('items', 'required_keys', 'fallback')
14561463

14571464
items: "OrderedDict[str, Type]" # item_name -> item_type
14581465
required_keys: Set[str]

0 commit comments

Comments
 (0)