Skip to content

Commit def5daf

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Add _static.pyi to _cinderx extension
Summary: Helps type the Static Python compiler code. Moves the .pyi file closer to the _cinderx extension definition so pyre/pyrefly can actually pick it up. Reviewed By: DinoV Differential Revision: D93675597 fbshipit-source-id: 1ffe3458a8e199011d7ff067d4fbd509b7d98d34
1 parent ad9ae0e commit def5daf

File tree

5 files changed

+162
-130
lines changed

5 files changed

+162
-130
lines changed

cinderx/PythonLib/cinderx/static.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
# pyre-strict
33

44
from _cinderx import StaticTypeError
5-
6-
# pyre-ignore[21]: _static is defined as part of _cinderx.
7-
from _static import ( # noqa: F401
5+
from _static import (
86
__build_cinder_class__,
97
_clear_dlopen_cache,
108
_clear_dlsym_cache,
119
_property_missing_fget,
1210
_property_missing_fset,
1311
_sizeof_dlopen_cache,
1412
_sizeof_dlsym_cache,
15-
# Checked Containers
1613
chkdict,
1714
chklist,
1815
FAST_LEN_ARRAY,
@@ -84,12 +81,10 @@
8481
SEQ_REPEAT_REVERSED,
8582
SEQ_SUBSCR_UNCHECKED,
8683
SEQ_TUPLE,
87-
# Static Methods,
8884
set_type_code,
8985
set_type_final,
9086
set_type_static,
9187
set_type_static_final,
92-
# Static Classes
9388
staticarray,
9489
TYPED_ARRAY,
9590
TYPED_BOOL,

cinderx/PythonLib/stubs/_static.pyi

Lines changed: 0 additions & 124 deletions
This file was deleted.

cinderx/PythonLib/test_cinderx/test___static__/test_native_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,21 @@ def test_native_lookup_incorrect_argcount(self) -> None:
7272
with self.assertRaisesRegex(
7373
TypeError, "lookup_native_symbol: Expected 2 arguments"
7474
):
75+
# pyre-ignore[20]: Intentional type error, checking runtime behavior.
7576
lookup_native_symbol("lol")
7677

7778
def test_native_lookup_bad_lib_name(self) -> None:
7879
with self.assertRaisesRegex(
7980
TypeError, "classloader: 'lib_name' must be a str, got 'int'"
8081
):
82+
# pyre-ignore[6]: Intentional type error, checking runtime behavior.
8183
lookup_native_symbol(1, "labs")
8284

8385
def test_native_lookup_bad_symbol_name(self) -> None:
8486
with self.assertRaisesRegex(
8587
TypeError, "classloader: 'symbol_name' must be a str, got 'int'"
8688
):
89+
# pyre-ignore[6]: Intentional type error, checking runtime behavior.
8790
lookup_native_symbol("libc.so.6", 42)
8891

8992
def test_native_lookup_nonexistent_lib_name(self) -> None:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_set(self) -> None:
4545
with self.assertRaisesRegex(
4646
TypeError, "'object' object cannot be interpreted as an integer"
4747
):
48+
# pyre-ignore[6]: Intentional type error, checking runtime behavior.
4849
my_array[0] = object()
4950

5051
def test_get(self) -> None:

cinderx/_static.pyi

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
3+
# pyre-strict
4+
5+
from __future__ import annotations
6+
7+
from typing import Iterable, Iterator, NoReturn, TypeVar
8+
9+
TYPED_INT_UNSIGNED: int
10+
TYPED_INT_SIGNED: int
11+
12+
TYPED_INT_8BIT: int
13+
TYPED_INT_16BIT: int
14+
TYPED_INT_32BIT: int
15+
TYPED_INT_64BIT: int
16+
17+
TYPED_INT8: int
18+
TYPED_INT16: int
19+
TYPED_INT32: int
20+
TYPED_INT64: int
21+
22+
TYPED_UINT8: int
23+
TYPED_UINT16: int
24+
TYPED_UINT32: int
25+
TYPED_UINT64: int
26+
27+
TYPED_OBJECT: int
28+
TYPED_DOUBLE: int
29+
TYPED_SINGLE: int
30+
TYPED_CHAR: int
31+
TYPED_BOOL: int
32+
TYPED_VOID: int
33+
TYPED_STRING: int
34+
TYPED_ERROR: int
35+
TYPED_ARRAY: int
36+
37+
SEQ_LIST: int
38+
SEQ_TUPLE: int
39+
SEQ_LIST_INEXACT: int
40+
SEQ_ARRAY_INT64: int
41+
SEQ_SUBSCR_UNCHECKED: int
42+
43+
SEQ_REPEAT_INEXACT_SEQ: int
44+
SEQ_REPEAT_INEXACT_NUM: int
45+
SEQ_REPEAT_REVERSED: int
46+
SEQ_REPEAT_PRIMITIVE_NUM: int
47+
48+
SEQ_CHECKED_LIST: int
49+
50+
PRIM_OP_EQ_INT: int
51+
PRIM_OP_NE_INT: int
52+
PRIM_OP_LT_INT: int
53+
PRIM_OP_LE_INT: int
54+
PRIM_OP_GT_INT: int
55+
PRIM_OP_GE_INT: int
56+
PRIM_OP_LT_UN_INT: int
57+
PRIM_OP_LE_UN_INT: int
58+
PRIM_OP_GT_UN_INT: int
59+
PRIM_OP_GE_UN_INT: int
60+
PRIM_OP_EQ_DBL: int
61+
PRIM_OP_NE_DBL: int
62+
PRIM_OP_LT_DBL: int
63+
PRIM_OP_LE_DBL: int
64+
PRIM_OP_GT_DBL: int
65+
PRIM_OP_GE_DBL: int
66+
67+
PRIM_OP_ADD_INT: int
68+
PRIM_OP_SUB_INT: int
69+
PRIM_OP_MUL_INT: int
70+
PRIM_OP_DIV_INT: int
71+
PRIM_OP_DIV_UN_INT: int
72+
PRIM_OP_MOD_INT: int
73+
PRIM_OP_MOD_UN_INT: int
74+
PRIM_OP_POW_INT: int
75+
PRIM_OP_POW_UN_INT: int
76+
PRIM_OP_LSHIFT_INT: int
77+
PRIM_OP_RSHIFT_INT: int
78+
PRIM_OP_RSHIFT_UN_INT: int
79+
PRIM_OP_XOR_INT: int
80+
PRIM_OP_OR_INT: int
81+
PRIM_OP_AND_INT: int
82+
83+
PRIM_OP_ADD_DBL: int
84+
PRIM_OP_SUB_DBL: int
85+
PRIM_OP_MUL_DBL: int
86+
PRIM_OP_DIV_DBL: int
87+
PRIM_OP_MOD_DBL: int
88+
PRIM_OP_POW_DBL: int
89+
90+
PRIM_OP_NEG_INT: int
91+
PRIM_OP_INV_INT: int
92+
PRIM_OP_NEG_DBL: int
93+
PRIM_OP_NOT_INT: int
94+
95+
FAST_LEN_INEXACT: int
96+
FAST_LEN_LIST: int
97+
FAST_LEN_DICT: int
98+
FAST_LEN_SET: int
99+
FAST_LEN_TUPLE: int
100+
FAST_LEN_ARRAY: int
101+
FAST_LEN_STR: int
102+
103+
RAND_MAX: int
104+
105+
T = TypeVar("T")
106+
K = TypeVar("K")
107+
V = TypeVar("V")
108+
109+
chklist = list[T]
110+
chkdict = dict[K, V]
111+
112+
class staticarray(Iterable[int]):
113+
@classmethod
114+
def __init__(cls, size: int) -> None: ...
115+
@classmethod
116+
def __class_getitem__(cls, key: type[object]) -> type[object]: ...
117+
def __add__(self, other: staticarray) -> staticarray: ...
118+
def __mul__(self, repeat: int) -> staticarray: ...
119+
def __rmul__(self, repeat: int) -> staticarray: ...
120+
def __delitem__(self, index: int) -> None: ...
121+
def __getitem__(self, index: int) -> int: ...
122+
def __setitem__(self, index: int, value: int) -> None: ...
123+
def __len__(self) -> int: ...
124+
def __repr__(self) -> str: ...
125+
126+
# This is a lie, staticarray doesn't have an __iter__ method. This is here so that
127+
# calling `list(static_array)` will work. `list()` is typed as taking an
128+
# Iterable[T], and that doesn't understand Python's support of __getitem__()-based
129+
# iterables.
130+
def __iter__(self) -> Iterator[int]: ...
131+
132+
def __build_cinder_class__(
133+
func: object, name: str, *bases: object, **kwds: object
134+
) -> type[object]: ...
135+
def _clear_dlopen_cache() -> None: ...
136+
def _clear_dlsym_cache() -> None: ...
137+
def _property_missing_fdel(base: object, key: object) -> NoReturn: ...
138+
def _property_missing_fget(base: object) -> NoReturn: ...
139+
def _property_missing_fset(base: object, key: object) -> NoReturn: ...
140+
def _sizeof_dlopen_cache() -> int: ...
141+
def _sizeof_dlsym_cache() -> int: ...
142+
def init_subclass(ty: type[object]) -> None: ...
143+
def install_sp_audit_hook() -> None: ...
144+
def is_static_callable(obj: object) -> bool: ...
145+
def is_static_module(mod: object) -> bool: ...
146+
def is_type_static(ty: type[object]) -> bool: ...
147+
def lookup_native_symbol(lib: str, symbol: str) -> int: ...
148+
def make_context_decorator_wrapper(
149+
ctx_wrapper: object, wrapper_func: object, func: object
150+
) -> object: ...
151+
def make_recreate_cm(ty: type[object]) -> object: ...
152+
def rand() -> int: ...
153+
def resolve_primitive_descr(descr: object) -> int: ...
154+
def set_type_code(ty: type[object], code: int) -> None: ...
155+
def set_type_final(ty: type[object]) -> type[object]: ...
156+
def set_type_static(ty: type[object]) -> type[object]: ...
157+
def set_type_static_final(ty: type[object]) -> type[object]: ...

0 commit comments

Comments
 (0)