Skip to content

Commit 3acdf54

Browse files
rwbartongvanrossum
authored andcommitted
Remove some unnecessary checks for None (python#1464)
* Less paranoia in generating constraints for TypeVarType self.actual is declared as having type Type, and (as of commit b602ecc) cannot be None. * Less paranoia in TypeInfo.is_generic self.variables is declared as having type List[TypeVarDef], and can never be None.
1 parent d6a3453 commit 3acdf54

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

mypy/constraints.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ def visit_partial_type(self, template: PartialType) -> List[Constraint]:
163163
# Non-trivial leaf type
164164

165165
def visit_type_var(self, template: TypeVarType) -> List[Constraint]:
166-
if self.actual:
167-
return [Constraint(template.id, self.direction, self.actual)]
168-
else:
169-
return []
166+
return [Constraint(template.id, self.direction, self.actual)]
170167

171168
# Non-leaf types
172169

mypy/nodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ def fullname(self) -> str:
17761776

17771777
def is_generic(self) -> bool:
17781778
"""Is the type generic (i.e. does it have type variables)?"""
1779-
return self.type_vars is not None and len(self.type_vars) > 0
1779+
return len(self.type_vars) > 0
17801780

17811781
def get(self, name: str) -> 'SymbolTableNode':
17821782
for cls in self.mro:

0 commit comments

Comments
 (0)