11# Copyright (c) Meta Platforms, Inc. and affiliates.
22
3+ import __static__
4+
35import ast
46import asyncio
57import builtins
1517from tempfile import TemporaryDirectory
1618from textwrap import dedent
1719from types import ModuleType
18- from typing import Callable
20+ from typing import Callable , cast
1921from unittest import skip , skipIf , skipUnless
2022from unittest .mock import patch
2123
4749 type_mismatch ,
4850)
4951
52+ STATIC_PATH : str = path .dirname (path .dirname (__static__ .__file__ ))
53+
5054RICHARDS_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\n a: 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 :
0 commit comments