Skip to content

Commit 299b52e

Browse files
committed
Improve some tests and fix an issue
1 parent 74f314e commit 299b52e

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

mypyc/emitwrapper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ def generate_hash_wrapper(cl: ClassIR, fn: FuncIR, emitter: Emitter) -> str:
175175
emitter.emit_line('static Py_ssize_t {name}(PyObject *self) {{'.format(
176176
name=name
177177
))
178-
emitter.emit_line('{}retval = {}{}(self);'.format(emitter.ctype_spaced(fn.ret_type),
179-
NATIVE_PREFIX,
180-
fn.cname(emitter.names)))
178+
emitter.emit_line('{}retval = {}{}{}(self);'.format(emitter.ctype_spaced(fn.ret_type),
179+
emitter.get_lib_prefix(fn.decl),
180+
NATIVE_PREFIX,
181+
fn.cname(emitter.names)))
181182
emitter.emit_error_check('retval', fn.ret_type, 'return -1;')
182183
if is_int_rprimitive(fn.ret_type):
183184
emitter.emit_line('Py_ssize_t val = CPyTagged_AsSsize_t(retval);')

mypyc/test-data/run-multimodule.test

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ else:
9090

9191
[case testMultiModuleImportClass]
9292
from typing import cast
93-
from other import C
93+
from other import C, a_global
9494

9595
class D(C):
9696
def __init__(self, x: int) -> None:
@@ -100,21 +100,32 @@ def f(c: C) -> int:
100100
d = D(3)
101101
o: object = c
102102
c = cast(C, o)
103-
return c.x + c.f() + d.x + d.f() + 1
103+
return a_global + c.x + c.f() + d.x + d.f() + 1
104104
[file other.py]
105+
from typing_extensions import Final
106+
a_global: Final = int('5')
107+
105108
class C:
106109
x: int
107110

108111
def __init__(self, x: int) -> None:
109112
self.x = x
110113

114+
def __hash__(self) -> int:
115+
return self.x
116+
117+
def __str__(self) -> str:
118+
return str(self.x)
119+
111120
def f(self) -> int:
112121
return 2
113122
[file driver.py]
114-
from native import f
123+
from native import f, D
115124
from other import C
116125
c = C(4)
117-
assert f(c) == 4 + 2 + 3 + 2 + 1
126+
assert f(c) == 5 + 4 + 2 + 3 + 2 + 1
127+
assert str(D(10)) == '10'
128+
assert hash(10) == 10
118129
try:
119130
f(1)
120131
except TypeError:

0 commit comments

Comments
 (0)