Skip to content

Commit

Permalink
Get pytype opensource tests passing.
Browse files Browse the repository at this point in the history
* Removes extraneous whitespace.
* Changes or silences tests that were failing in 3.9-.

PiperOrigin-RevId: 540723497
  • Loading branch information
rchen152 committed Jun 15, 2023
1 parent f037793 commit 3a8efa5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion pytype/block_environment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,3 @@ def test_self_edge(self):

if __name__ == "__main__":
unittest.main()

2 changes: 2 additions & 0 deletions pytype/tests/test_control_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"""

from pytype.tests import test_base
from pytype.tests import test_utils


@test_utils.skipBeforePy((3, 10), "Depends on 3.10+ bytecode")
class TestControlFlow(test_base.BaseTest):
"""Tests for control flow related features."""

Expand Down
8 changes: 5 additions & 3 deletions pytype/tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,9 @@ def parse(self) -> Features[F]:
return result
""")

def test_if_statement_name_error(self):
def test_if_statement(self):
# See b/195136939
self.CheckWithErrors("""
self.Check("""
import enum
class M(enum.Enum):
A = 1
Expand All @@ -957,7 +957,9 @@ def f(m: M) -> int:
x = 1
elif m == M.B:
x = 2
return x + 1 # name-error
else:
x = 3
return x + 1
class A:
def __init__(self, m: M):
Expand Down
5 changes: 3 additions & 2 deletions pytype/tests/test_variable_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@ def f():
self.assertTypesMatchPytd(ty, "def f() -> int: ...")

def test_multi_statement_line(self):
ty, _ = self.InferWithErrors("""
ty = self.Infer("""
def f():
if __random__: v: int = None
return v # name-error
else: v = __any_object__
return v
""")
self.assertTypesMatchPytd(ty, """
from typing import Any
Expand Down
3 changes: 2 additions & 1 deletion pytype/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@ def load_local(self, state, name):
# variable at the current node with var's bindings and return that. For now,
# we just use this as a reachability check to make sure `name` is defined in
# every path through the code.
if self.ctx.options.strict_undefined_checks and not var:
if (self.ctx.options.strict_undefined_checks and
self.ctx.python_version >= (3, 10) and not var):
raise KeyError()

return self.load_from(state, self.frame.f_locals, name)
Expand Down

0 comments on commit 3a8efa5

Please sign in to comment.