Skip to content

Commit

Permalink
Improve process_placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed May 6, 2023
1 parent fd1aeab commit e5d9c3c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,13 +1064,11 @@ def setup_self_type(self) -> None:
assert self.type is not None
info = self.type
if info.self_type is not None:
if has_placeholder(info.self_type.upper_bound) or has_placeholder(
info.self_type.default
):
if has_placeholder(info.self_type.upper_bound):
# Similar to regular (user defined) type variables.
self.process_placeholder(
None,
"Self upper bound or default",
"Self upper bound",
info,
force_progress=info.self_type.upper_bound != fill_typevars(info),
)
Expand Down Expand Up @@ -4026,14 +4024,12 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> bool:
call.analyzed.upper_bound = upper_bound
call.analyzed.values = values
call.analyzed.default = default
if (
any(has_placeholder(v) for v in values)
or has_placeholder(upper_bound)
or has_placeholder(default)
):
self.process_placeholder(
None, "TypeVar values, upper bound, or default", s, force_progress=updated
)
if any(has_placeholder(v) for v in values):
self.process_placeholder(None, "TypeVar values", s, force_progress=updated)
elif has_placeholder(upper_bound):
self.process_placeholder(None, "TypeVar upper bound", s, force_progress=updated)
elif has_placeholder(default):
self.process_placeholder(None, "TypeVar default", s, force_progress=updated)

self.add_symbol(name, call.analyzed, s)
return True
Expand Down Expand Up @@ -4209,8 +4205,14 @@ def process_paramspec_declaration(self, s: AssignmentStmt) -> bool:
)
paramspec_var.line = call.line
call.analyzed = paramspec_var
updated = True
else:
assert isinstance(call.analyzed, ParamSpecExpr)
updated = default != call.analyzed.default
call.analyzed.default = default
if has_placeholder(default):
self.process_placeholder(None, "ParamSpec default", s, force_progress=updated)

self.add_symbol(name, call.analyzed, s)
return True

Expand Down Expand Up @@ -4250,8 +4252,14 @@ def process_typevartuple_declaration(self, s: AssignmentStmt) -> bool:
)
typevartuple_var.line = call.line
call.analyzed = typevartuple_var
updated = True
else:
assert isinstance(call.analyzed, TypeVarTupleExpr)
updated = default != call.analyzed.default
call.analyzed.default = default
if has_placeholder(default):
self.process_placeholder(None, "TypeVarTuple default", s, force_progress=updated)

self.add_symbol(name, call.analyzed, s)
return True

Expand Down

0 comments on commit e5d9c3c

Please sign in to comment.