Skip to content

Commit e34b453

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
{Pyrefly] Add property test and support
Summary: Adds a test case for invoking properties - fixes the one issue which causes inexact code gen where we are getting exact types by default. Reviewed By: martindemello Differential Revision: D96226921 fbshipit-source-id: df661444f4a66a2ba672941bd2e7fada495e674b
1 parent 5fec65f commit e34b453

6 files changed

Lines changed: 137 additions & 59 deletions

File tree

cinderx/PythonLib/cinderx/compiler/static/pyrefly_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from cinderx.compiler.static.pyrefly_info import EMPTY_TYPE_INFO, Pyrefly
99
from cinderx.compiler.static.pyrefly_type_binder import PyreflyTypeBinder
1010
from cinderx.compiler.static.type_binder import TypeBinder
11-
from cinderx.compiler.strict.compiler import Compiler
11+
from cinderx.compiler.strict.compiler import Compiler, TIMING_LOGGER_TYPE
1212
from cinderx.compiler.strict.flag_extractor import Flags
1313
from cinderx.compiler.symbols import SymbolVisitor
1414

cinderx/PythonLib/cinderx/compiler/static/pyrefly_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def resolve_classname(
186186
if result is None:
187187
return None
188188
if isinstance(result, Class):
189-
return result
189+
return result.inexact_type()
190190
elif isinstance(result, Value):
191191
return result.klass
192192
return None

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

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"type_table": [
3+
{
4+
"kind": "class",
5+
"qname": "builtins.property",
6+
"args": [],
7+
"hash": 6891147978376177783
8+
},
9+
{
10+
"kind": "other_form",
11+
"qname": "typing.Type",
12+
"args": [
13+
0
14+
],
15+
"hash": 1202475085224118155
16+
},
17+
{
18+
"kind": "class",
19+
"qname": "builtins.int",
20+
"args": [],
21+
"hash": 7437843174258217660
22+
},
23+
{
24+
"kind": "other_form",
25+
"qname": "typing.Type",
26+
"args": [
27+
2
28+
],
29+
"hash": 6510812805515236383
30+
},
31+
{
32+
"kind": "literal",
33+
"value": "42",
34+
"promoted_type": 2,
35+
"hash": 8499067216537500750
36+
},
37+
{
38+
"kind": "class",
39+
"qname": "cinderx.PythonLib.test_cinderx.test_compiler.test_static.pyreflytests.property.C",
40+
"args": [],
41+
"hash": 18418907475535762116
42+
},
43+
{
44+
"kind": "other_form",
45+
"qname": "typing.Type",
46+
"args": [
47+
5
48+
],
49+
"hash": 3047767295098807706
50+
}
51+
],
52+
"locations": [
53+
{
54+
"loc": {
55+
"start_line": 2,
56+
"start_col": 5,
57+
"end_line": 2,
58+
"end_col": 13
59+
},
60+
"type": 1
61+
},
62+
{
63+
"loc": {
64+
"start_line": 3,
65+
"start_col": 19,
66+
"end_line": 3,
67+
"end_col": 22
68+
},
69+
"type": 3
70+
},
71+
{
72+
"loc": {
73+
"start_line": 4,
74+
"start_col": 15,
75+
"end_line": 4,
76+
"end_col": 17
77+
},
78+
"type": 4
79+
},
80+
{
81+
"loc": {
82+
"start_line": 7,
83+
"start_col": 11,
84+
"end_line": 7,
85+
"end_col": 14
86+
},
87+
"type": 3
88+
},
89+
{
90+
"loc": {
91+
"start_line": 8,
92+
"start_col": 11,
93+
"end_line": 8,
94+
"end_col": 16
95+
},
96+
"type": 2
97+
},
98+
{
99+
"loc": {
100+
"start_line": 8,
101+
"start_col": 11,
102+
"end_line": 8,
103+
"end_col": 14
104+
},
105+
"type": 5
106+
},
107+
{
108+
"loc": {
109+
"start_line": 8,
110+
"start_col": 11,
111+
"end_line": 8,
112+
"end_col": 12
113+
},
114+
"type": 6
115+
}
116+
]
117+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class C:
2+
@property
3+
def f(self) -> int:
4+
return 42
5+
6+
7+
def g() -> int:
8+
return C().f
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from types import CodeType
2+
3+
from test_cinderx.test_compiler.test_static.pyrefly_binder import PyreBinderTests
4+
5+
6+
def verify(test: PyreBinderTests, code: CodeType) -> None:
7+
"""Verify that the compiled code includes INVOKE_METHOD."""
8+
9+
g = test.find_code(code, "g")
10+
test.assertInBytecode(g, "INVOKE_METHOD")

0 commit comments

Comments
 (0)