Skip to content

Commit 682d699

Browse files
alexmalyshevfacebook-github-bot
authored andcommitted
Use cpp_python_extension() for xxclassloader, remove it from 3.10.cinder
Summary: This is a native extension for testing Static Python. It doesn't have to be part of the 3.10.cinder runtime and accessible to everyone. Only the CinderX tests care about it. Reviewed By: itamaro, DinoV Differential Revision: D78563987 fbshipit-source-id: cb483e0b4f7f5b51a1eae8747540f5691d6715a5
1 parent 1b68386 commit 682d699

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

cinderx/PythonLib/test_cinderx/test_compiler/test_static/compile.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22

3+
import __static__
4+
35
import ast
46
import asyncio
57
import builtins
@@ -15,7 +17,7 @@
1517
from tempfile import TemporaryDirectory
1618
from textwrap import dedent
1719
from types import ModuleType
18-
from typing import Callable
20+
from typing import Callable, cast
1921
from unittest import skip, skipIf, skipUnless
2022
from unittest.mock import patch
2123

@@ -47,6 +49,8 @@
4749
type_mismatch,
4850
)
4951

52+
STATIC_PATH: str = path.dirname(path.dirname(__static__.__file__))
53+
5054
RICHARDS_PATH = path.join(
5155
path.dirname(__file__),
5256
"..",
@@ -786,7 +790,7 @@ def test_type_is_exact(self) -> None:
786790

787791
def test_bind_instance(self) -> None:
788792
mod, comp = self.bind_module("class C: pass\na: C = C()")
789-
assign = mod.body[1]
793+
assign = cast(ast.AnnAssign, mod.body[1])
790794
types = comp.modules["foo"].types
791795
self.assertEqual(types[assign.target].name, "foo.C")
792796
self.assertEqual(repr(types[assign.target]), "<foo.C>")
@@ -808,6 +812,7 @@ def f(a):
808812
x: bool = a
809813
"""
810814
acomp = self.compile_strict(code)
815+
assert acomp is not None
811816
x = self.find_code(acomp, "f")
812817
self.assertInBytecode(x, "CAST", ("builtins", "bool", "!"))
813818

@@ -818,6 +823,7 @@ def f(a):
818823
x: bool = a
819824
"""
820825
acomp = self.compile_strict(code)
826+
assert acomp is not None
821827
x = self.find_code(acomp, "f")
822828
self.assertInBytecode(x, "CAST", ("builtins", "bool", "!"))
823829

@@ -1905,6 +1911,8 @@ def test_invoke_builtin_func_ret_neg(self) -> None:
19051911
# do a direct invoke
19061912
xxclassloader = sys.modules["xxclassloader"]
19071913
try:
1914+
# pyre-ignore[6]: Pyre doesn't know that StrictModule is interchangeable
1915+
# with ModuleType.
19081916
sys.modules["xxclassloader"] = StrictModule(xxclassloader.__dict__, False)
19091917
codestr = """
19101918
from xxclassloader import neg
@@ -5107,6 +5115,8 @@ def f(self):
51075115
d = D()
51085116
for _ in range(100):
51095117
try:
5118+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible
5119+
# to pyre.
51105120
d.g().send(None)
51115121
except StopIteration as e:
51125122
self.assertEqual(e.args[0], 100)
@@ -5132,6 +5142,8 @@ def f(self):
51325142

51335143
d = D()
51345144
with self.assertRaises(TypeError):
5145+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to
5146+
# pyre.
51355147
d.g().send(None)
51365148
loop.close()
51375149

@@ -5236,6 +5248,7 @@ class D(mod.C):
52365248
async def f(self):
52375249
return 0
52385250

5251+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to pyre.
52395252
coro = D().g()
52405253
with self.assertRaises(IndexError):
52415254
coro.send(None)
@@ -5257,10 +5270,12 @@ class D(mod.C):
52575270
def f(self):
52585271
return loop.create_future()
52595272

5273+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to pyre.
52605274
coro = D().g()
52615275
try:
52625276
coro.send(None)
52635277
except RuntimeError as e:
5278+
# pyre-ignore[16]: Expecting __cause__ to exist.
52645279
self.assertEqual(e.__cause__.args[0], 100)
52655280
loop.close()
52665281

@@ -5281,6 +5296,7 @@ class D(mod.C):
52815296
def f(self):
52825297
return loop.create_future()
52835298

5299+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to pyre.
52845300
coro = D().g()
52855301
with self.assertRaises(TypeError):
52865302
coro.send(None)
@@ -5302,6 +5318,7 @@ class D(mod.C):
53025318
async def f(self):
53035319
return 0
53045320

5321+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to pyre.
53055322
coro = D().g()
53065323
try:
53075324
coro.send(None)
@@ -5584,6 +5601,7 @@ def g():
55845601
(((mod.__name__,), "f"), 0),
55855602
)
55865603

5604+
# pyre-ignore[56]: skip_unless_jit isn't fully typed yet.
55875605
@skip_unless_jit("runs subprocess with JIT")
55885606
def test_invoke_recursive_compile_respects_jitlist(self) -> None:
55895607
with TemporaryDirectory() as d:
@@ -5628,7 +5646,9 @@ def f3():
56285646
"install-strict-loader",
56295647
"main.py",
56305648
]
5631-
proc = subprocess.run(cmd, capture_output=True, cwd=str(d))
5649+
proc = subprocess.run(
5650+
cmd, capture_output=True, cwd=str(d), env={"PYTHONPATH": STATIC_PATH}
5651+
)
56325652
self.assertEqual(proc.returncode, 0, proc.stderr)
56335653

56345654
def test_module_level_final_decl(self) -> None:

cinderx/PythonLib/test_cinderx/test_compiler/test_static/patch.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@
88
from unittest.mock import MagicMock, Mock, patch
99

1010
try:
11-
from cinderx import getknobs, setknobs
11+
from cinder import getknobs, setknobs
1212
except ImportError:
1313
getknobs = setknobs = None
1414

15+
import xxclassloader
1516

1617
from cinderx.compiler.pycodegen import PythonCodeGenerator
1718

18-
from test.support.import_helper import import_module
19-
2019
from .common import StaticTestBase
2120

22-
xxclassloader = import_module("xxclassloader")
23-
2421

2522
@contextmanager
2623
def save_restore_knobs():
@@ -195,6 +192,7 @@ def g(d):
195192
f = mod.f
196193
import weakref
197194

195+
# pyre-ignore[61]: Not using `i` here.
198196
wr = weakref.ref(f, lambda *args: self.assertEqual(i, -1)) # noqa: F841
199197
del f
200198
for _ in range(100):
@@ -221,6 +219,7 @@ def g():
221219
autospec=True,
222220
return_value=100,
223221
):
222+
# pyre-ignore[6]: Intentionally setting an integer key to mess with the module dict.
224223
mod.__dict__[42] = 1
225224
self.assertEqual(g(), 100)
226225

@@ -556,7 +555,9 @@ class D(C):
556555

557556
C.f = 42
558557
a = D()
558+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to pyre.
559559
a.f = 100
560+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to pyre.
560561
self.assertEqual(a.get_f(), 100)
561562

562563
def test_patch_static_to_static(self) -> None:
@@ -605,6 +606,8 @@ class E(D):
605606
with self.assertRaisesRegex(
606607
TypeError, "unexpected return type from E.f, expected str, got int"
607608
):
609+
# pyre-ignore[16]: Superclass is dynamically compiled and invisible to
610+
# pyre.
608611
self.assertEqual(E().get_lower_f(), "ABC")
609612

610613
def test_patch_method_mock(self) -> None:
@@ -1668,7 +1671,7 @@ def __get__(self, inst, ctx):
16681671
with self.in_module(codestr) as mod:
16691672
self.assertEqual(mod.f(mod.C()), 1)
16701673
mod.C.prop = Desc()
1671-
self.assertRaises(
1674+
self.assertRaisesRegex(
16721675
TypeError,
16731676
"unexpected return type from C.prop, expected int, got str",
16741677
mod.f,

0 commit comments

Comments
 (0)