Skip to content

Commit

Permalink
remove redundant specification of StaticCodeGenerator
Browse files Browse the repository at this point in the history
Summary:
While I was in a codemodding mood, this particular bit of redundant verbosity has always
bugged me, so now it's gone. Don't bring it back! Static code generator should be the
expected default for static python tests.

Reviewed By: DinoV

Differential Revision: D31449256

fbshipit-source-id: 7e4357b
  • Loading branch information
Carl Meyer authored and facebook-github-bot committed Oct 6, 2021
1 parent 6664c4d commit b533913
Show file tree
Hide file tree
Showing 5 changed files with 596 additions and 644 deletions.
4 changes: 3 additions & 1 deletion Lib/test/test_compiler/test_static/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ def _run_code(self, code, generator, modname, peephole_enabled):
exec(compiled, d)
return modname, d

def run_code(self, code, generator=None, modname=None, peephole_enabled=True):
def run_code(
self, code, generator=StaticCodeGenerator, modname=None, peephole_enabled=True
):
_, r = self._run_code(code, generator, modname, peephole_enabled)
return r

Expand Down
15 changes: 7 additions & 8 deletions Lib/test/test_compiler/test_static/enum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from compiler.static import StaticCodeGenerator
from compiler.static.types import TypedSyntaxError

from _static import PRIM_OP_EQ_INT, TYPED_INT64
Expand All @@ -18,7 +17,7 @@ class Foo(int, Enum):
TypedSyntaxError,
"Static Enum types cannot support multiple bases:",
):
self.compile(codestr, StaticCodeGenerator)
self.compile(codestr)

def test_subclassing_unsupported(self):
codestr = """
Expand All @@ -34,7 +33,7 @@ class Bar(Foo):
TypedSyntaxError,
"Static Enum types do not allow subclassing",
):
self.compile(codestr, StaticCodeGenerator)
self.compile(codestr)

def test_compare_with_int_disallowed(self):
codestr = """
Expand All @@ -50,7 +49,7 @@ def is_set(bit: Bit) -> bool:
with self.assertRaisesRegex(
TypedSyntaxError, r"can't compare foo\.Bit to Literal\[1\]"
):
self.compile(codestr, StaticCodeGenerator, "foo")
self.compile(codestr, modname="foo")

def test_compare_different_enums_disallowed(self):
codestr = """
Expand All @@ -72,7 +71,7 @@ def foo() -> bool:
TypedSyntaxError,
r"can't compare <foo\.Bit\.ZERO: 0> to <foo\.Color\.RED: 0>",
):
self.compile(codestr, StaticCodeGenerator, "foo")
self.compile(codestr, modname="foo")

def test_reverse_compare_with_int_disallowed(self):
codestr = """
Expand All @@ -88,7 +87,7 @@ def is_set(bit: Bit) -> bool:
with self.assertRaisesRegex(
TypedSyntaxError, r"can't compare Literal\[1\] to foo\.Bit"
):
self.compile(codestr, StaticCodeGenerator, "foo")
self.compile(codestr, modname="foo")

def test_delattr_disallowed(self):
codestr = """
Expand All @@ -107,7 +106,7 @@ def north_pole() -> None:
with self.assertRaisesRegex(
TypedSyntaxError, "Enum values cannot be modified or deleted"
):
self.compile(codestr, StaticCodeGenerator)
self.compile(codestr)

def test_setattr_disallowed(self):
codestr = """
Expand All @@ -124,7 +123,7 @@ def redshift() -> None:
with self.assertRaisesRegex(
TypedSyntaxError, "Enum values cannot be modified or deleted"
):
self.compile(codestr, StaticCodeGenerator)
self.compile(codestr)

def test_enum_function_arg_and_return_type(self):
codestr = """
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_compiler/test_static/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
from compiler.static import StaticCodeGenerator
from compiler.static.errors import TypedSyntaxError
from types import MemberDescriptorType

Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_compiler/test_static/patch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import re
from compiler.pycodegen import PythonCodeGenerator
from compiler.static import StaticCodeGenerator
from unittest.mock import Mock, patch

from .common import StaticTestBase
Expand Down Expand Up @@ -595,7 +594,7 @@ def x(c: C):
return x
"""

code = self.compile(codestr, StaticCodeGenerator, modname="foo")
code = self.compile(codestr, modname="foo")
x = self.find_code(code, "x")
self.assertInBytecode(x, "INVOKE_METHOD", (("foo", "C", "f"), 0))

Expand All @@ -617,7 +616,7 @@ def x(c: C):
return x
"""

code = self.compile(codestr, StaticCodeGenerator, modname="foo")
code = self.compile(codestr, modname="foo")
x = self.find_code(code, "x")
self.assertInBytecode(x, "INVOKE_METHOD", (("foo", "C", "f"), 0))

Expand Down
Loading

0 comments on commit b533913

Please sign in to comment.