Skip to content

Commit 162ec87

Browse files
Completely rework Handle Import algorithm
It now handles global variables and works in a straight-forward way, similar to a preprocessor.
1 parent 7353240 commit 162ec87

10 files changed

+292
-400
lines changed

pythran/tests/test_import_all.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def unsupported_module():
3333
with self.assertRaises(pythran.syntax.PythranSyntaxError) as ex:
3434
pythran.compile_pythrancode("flamby", dedent(code))
3535

36-
self.assertIn("Module 'collections' unknown and not found.",
37-
str(ex.exception))
36+
self.assertIn("Module 'collections' not found.", str(ex.exception))
3837

3938
def test_complex_import_manipulation(self):
4039
"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def dint():
2+
return int()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import builtins_in_imported
2+
from builtins_in_imported import dint
3+
4+
5+
#pythran export entry()
6+
#runas entry()
7+
def entry():
8+
return dint(), builtins_in_imported.dint()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def aa():
2+
return 3.14
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import global_init as gi
2+
3+
4+
XX = [gi.aa(), 3]
5+
6+
#pythran export bb()
7+
def bb():
8+
return XX
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from .global_init import aa
2+
3+
def cc():
4+
return aa()
5+
6+
7+
XX = [aa(), 3]
8+
9+
#pythran export bb()
10+
def bb():
11+
return XX
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def aa(a):
2+
ret = []
3+
while a > 2:
4+
ret.append(0)
5+
a -=1
6+
return ret
7+
8+
def hh(value):
9+
ret = []
10+
while value > 0:
11+
a, b = _div_tuple(value, 10)
12+
ret.insert(0, 0)
13+
value = a
14+
return ret
15+
16+
17+
def _div_tuple(base, div):
18+
a = base // div
19+
b = base % div
20+
return a, b
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from .method_in_imported_module import aa, hh
2+
from .other_method_in_imported_module import CC, DD
3+
4+
def cc():
5+
return aa(3)
6+
7+
8+
9+
#pythran export dd(int)
10+
def dd(o):
11+
return hh(o)
12+
13+
14+
XX = cc() + [3]
15+
YY = CC()
16+
17+
#pythran export bb()
18+
def bb():
19+
return XX, YY, DD()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .method_in_imported_module import aa
2+
# importing another module can produce funny things too
3+
def CC():
4+
return [aa(h) for h in range(10)]
5+
6+
def DD():
7+
return [CC for CC in range(10)]

0 commit comments

Comments
 (0)