Skip to content

Commit dc725bf

Browse files
committed
Remove debug prints
1 parent 1442d77 commit dc725bf

1 file changed

Lines changed: 0 additions & 56 deletions

File tree

mypy/partially_defined.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@
4848
from mypy.types import Type, UninhabitedType, get_proper_type
4949

5050

51-
def _ambv(s: str) -> None:
52-
assert s
53-
pass # print("DEBUG:", s)
54-
55-
56-
def _ambv_cont(s: str) -> None:
57-
assert s
58-
pass # print(s)
59-
60-
6151
class BranchState:
6252
"""BranchState contains information about variable definition at the end of a branching statement.
6353
`if` and `match` are examples of branching statements.
@@ -127,9 +117,6 @@ def delete_var(self, name: str) -> None:
127117
def record_nested_branch(self, state: BranchState) -> None:
128118
assert len(self.branches) > 0
129119
current_branch = self.branches[-1]
130-
_ambv(
131-
f"record_nested_branch: state.must={state.must_be_defined if 'value' in state.must_be_defined else '...'}, state.may={'value' if 'value' in state.may_be_defined else '...'}, state.skipped={state.skipped}"
132-
)
133120
if state.skipped:
134121
current_branch.skipped = True
135122
return
@@ -167,17 +154,6 @@ def done(self) -> BranchState:
167154
all_vars.update(b.must_be_defined)
168155
# For the rest of the things, we only care about branches that weren't skipped.
169156
non_skipped_branches = [b for b in self.branches if not b.skipped]
170-
import sys
171-
172-
_called_by = sys._getframe(2).f_code.co_name
173-
_ambv(
174-
f"done {_called_by}: branches={len(self.branches)}, non_skipped={len(non_skipped_branches)}"
175-
)
176-
for i, b in enumerate(self.branches):
177-
has_value = "value" in b.must_be_defined or "value" in b.may_be_defined
178-
_ambv_cont(
179-
f" Branch {i}: has_value={has_value}, skipped={b.skipped}, must={b.must_be_defined}, may={b.may_be_defined}"
180-
)
181157
if non_skipped_branches:
182158
must_be_defined = non_skipped_branches[0].must_be_defined
183159
for b in non_skipped_branches[1:]:
@@ -187,7 +163,6 @@ def done(self) -> BranchState:
187163
# Everything that wasn't defined in all branches but was defined
188164
# in at least one branch should be in `may_be_defined`!
189165
may_be_defined = all_vars.difference(must_be_defined)
190-
_ambv_cont(f" Result: must={must_be_defined}, may={may_be_defined}")
191166
return BranchState(
192167
must_be_defined=must_be_defined,
193168
may_be_defined=may_be_defined,
@@ -363,10 +338,6 @@ def __init__(
363338
for name in implicit_module_attrs:
364339
self.tracker.record_definition(name)
365340

366-
# def visit_block(self, block: Block, /) -> None:
367-
# _ambv(f"PossiblyUndefinedVariableVisitor visiting {block}")
368-
# super().visit_block(block)
369-
370341
def var_used_before_def(self, name: str, context: Context) -> None:
371342
if self.msg.errors.is_error_code_enabled(errorcodes.USED_BEFORE_DEF):
372343
self.msg.var_used_before_def(name, context)
@@ -380,9 +351,6 @@ def process_definition(self, name: str) -> None:
380351
if not self.tracker.in_scope(ScopeType.Class):
381352
refs = self.tracker.pop_undefined_ref(name)
382353
for ref in refs:
383-
_ambv(
384-
f"process_definition for {name}, ref at line {ref.line}, loops={bool(self.loops)}"
385-
)
386354
if self.loops:
387355
self.variable_may_be_undefined(name, ref)
388356
else:
@@ -404,9 +372,6 @@ def visit_nonlocal_decl(self, o: NonlocalDecl) -> None:
404372

405373
def process_lvalue(self, lvalue: Lvalue | None) -> None:
406374
if isinstance(lvalue, NameExpr):
407-
_ambv(
408-
f"process_lvalue calling process_definition for {lvalue.name} at line {lvalue.line}"
409-
)
410375
self.process_definition(lvalue.name)
411376
elif isinstance(lvalue, StarExpr):
412377
self.process_lvalue(lvalue.expr)
@@ -415,7 +380,6 @@ def process_lvalue(self, lvalue: Lvalue | None) -> None:
415380
self.process_lvalue(item)
416381

417382
def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
418-
_ambv(f"visit_assignment_stmt at line {o.line}")
419383
for lvalue in o.lvalues:
420384
self.process_lvalue(lvalue)
421385
super().visit_assignment_stmt(o)
@@ -494,34 +458,20 @@ def visit_dictionary_comprehension(self, o: DictionaryComprehension) -> None:
494458
self.tracker.exit_scope()
495459

496460
def visit_for_stmt(self, o: ForStmt) -> None:
497-
_ambv(f"visit_for_stmt: line {o.line}")
498461
o.expr.accept(self)
499462
self.process_lvalue(o.index)
500463
o.index.accept(self)
501464
self.tracker.start_branch_statement()
502465
loop = Loop()
503466
self.loops.append(loop)
504-
_ambv(
505-
f"visit_for_stmt: Before body, current state: {self.tracker._scope().branch_stmts[-1].branches[-1].must_be_defined}, may={self.tracker._scope().branch_stmts[-1].branches[-1].may_be_defined}"
506-
)
507467
o.body.accept(self)
508-
_ambv(f"visit_for_stmt: after body, has_break={loop.has_break}")
509-
_ambv(
510-
f"visit_for_stmt: After body, current state: {self.tracker._scope().branch_stmts[-1].branches[-1].must_be_defined}, may={self.tracker._scope().branch_stmts[-1].branches[-1].may_be_defined}"
511-
)
512468
self.tracker.next_branch()
513-
_ambv(
514-
f"visit_for_stmt: After next_branch, new branch state: {self.tracker._scope().branch_stmts[-1].branches[-1].must_be_defined}, may={self.tracker._scope().branch_stmts[-1].branches[-1].may_be_defined}"
515-
)
516469
self.tracker.end_branch_statement()
517470
if o.else_body is not None:
518471
# If the loop has a `break` inside, `else` is executed conditionally.
519472
# If the loop doesn't have a `break` either the function will return or
520473
# execute the `else`.
521474
has_break = loop.has_break
522-
_ambv(
523-
f"visit_for_stmt: else_body present, has_break={has_break}, break_vars={loop.break_vars}"
524-
)
525475
if has_break:
526476
self.tracker.start_branch_statement()
527477
if loop.break_vars is not None:
@@ -552,7 +502,6 @@ def visit_raise_stmt(self, o: RaiseStmt) -> None:
552502
self.tracker.skip_branch()
553503

554504
def visit_continue_stmt(self, o: ContinueStmt) -> None:
555-
_ambv(f"continue at line {o.line}, skipping branch")
556505
super().visit_continue_stmt(o)
557506
self.tracker.skip_branch()
558507

@@ -609,7 +558,6 @@ def f() -> int:
609558
self.try_depth -= 1
610559

611560
def process_try_stmt(self, o: TryStmt) -> None:
612-
_ambv(f"process_try_stmt: line {o.line}, handlers={len(o.handlers)}")
613561
"""
614562
Processes try statement decomposing it into the following:
615563
if ...:
@@ -685,9 +633,6 @@ def visit_starred_pattern(self, o: StarredPattern) -> None:
685633
def visit_name_expr(self, o: NameExpr) -> None:
686634
if o.name in self.builtins and self.tracker.in_scope(ScopeType.Global):
687635
return
688-
_ambv(
689-
f"visit_name_expr {o.name} at line {o.line}, possibly_undefined={self.tracker.is_possibly_undefined(o.name)}, defined_in_different_branch={self.tracker.is_defined_in_different_branch(o.name)}, is_undefined={self.tracker.is_undefined(o.name)}"
690-
)
691636
if self.tracker.is_possibly_undefined(o.name):
692637
# A variable is only defined in some branches.
693638
self.variable_may_be_undefined(o.name, o)
@@ -708,7 +653,6 @@ def visit_name_expr(self, o: NameExpr) -> None:
708653
# Case (1) will be caught by semantic analyzer. Case (2) is a forward ref that should
709654
# be caught by this visitor. Save the ref for later, so that if we see a definition,
710655
# we know it's a used-before-definition scenario.
711-
_ambv(f"Recording undefined ref for {o.name} at line {o.line}")
712656
self.tracker.record_undefined_ref(o)
713657
super().visit_name_expr(o)
714658

0 commit comments

Comments
 (0)