Skip to content

Commit 684e880

Browse files
authored
Implement more ast features (RustPython#6986)
1 parent 0919b2c commit 684e880

37 files changed

+3043
-421
lines changed

.cspell.dict/cpython.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ badcert
1010
badsyntax
1111
baseinfo
1212
basetype
13+
binop
1314
boolop
1415
BUILDSTDLIB
1516
bxor
@@ -73,6 +74,7 @@ HASPOINTER
7374
HASSTRUCT
7475
HASUNION
7576
heaptype
77+
hexdigit
7678
HIGHRES
7779
IFUNC
7880
IMMUTABLETYPE

Lib/test/test_ast/data/ast_repr.txt

Lines changed: 214 additions & 0 deletions
Large diffs are not rendered by default.

Lib/test/test_ast/test_ast.py

Lines changed: 0 additions & 65 deletions
Large diffs are not rendered by default.

Lib/test/test_builtin.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ def f(): """doc"""
445445
rv = ns['f']()
446446
self.assertEqual(rv, tuple(expected))
447447

448-
@unittest.expectedFailure # TODO: RUSTPYTHON
449448
def test_compile_top_level_await_no_coro(self):
450449
"""Make sure top level non-await codes get the correct coroutine flags"""
451450
modes = ('single', 'exec')
@@ -552,7 +551,6 @@ async def sleep(delay, result=None):
552551
run_yielding_async_fn(lambda: eval(co, globals_))
553552
self.assertEqual(globals_['a'], 1)
554553

555-
@unittest.expectedFailure # TODO: RUSTPYTHON
556554
def test_compile_top_level_await_invalid_cases(self):
557555
# helper function just to check we can run top=level async-for
558556
async def arange(n):
@@ -593,7 +591,6 @@ async def __aexit__(self, *exc_info):
593591
mode,
594592
flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
595593

596-
@unittest.expectedFailure # TODO: RUSTPYTHON
597594
def test_compile_async_generator(self):
598595
"""
599596
With the PyCF_ALLOW_TOP_LEVEL_AWAIT flag added in 3.8, we want to
@@ -640,7 +637,7 @@ def test_delattr(self):
640637
msg = r"^attribute name must be string, not 'int'$"
641638
self.assertRaisesRegex(TypeError, msg, delattr, sys, 1)
642639

643-
@unittest.expectedFailure # TODO: RUSTPYTHON
640+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '__repr__' unexpectedly found in ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', 'bar']
644641
def test_dir(self):
645642
# dir(wrong number of arguments)
646643
self.assertRaises(TypeError, dir, 42, 42)
@@ -894,7 +891,6 @@ def test_exec_kwargs(self):
894891
exec('global z\nz = 1', locals=g)
895892
self.assertEqual(g, {})
896893

897-
@unittest.expectedFailure # TODO: RUSTPYTHON
898894
def test_exec_globals(self):
899895
code = compile("print('Hello World!')", "", "exec")
900896
# no builtin function
@@ -904,7 +900,6 @@ def test_exec_globals(self):
904900
self.assertRaises(TypeError,
905901
exec, code, {'__builtins__': 123})
906902

907-
@unittest.expectedFailure # TODO: RUSTPYTHON
908903
def test_exec_globals_frozen(self):
909904
class frozendict_error(Exception):
910905
pass
@@ -937,7 +932,6 @@ def __setitem__(self, key, value):
937932
self.assertRaises(frozendict_error,
938933
exec, code, namespace)
939934

940-
@unittest.expectedFailure # TODO: RUSTPYTHON
941935
def test_exec_globals_error_on_get(self):
942936
# custom `globals` or `builtins` can raise errors on item access
943937
class setonlyerror(Exception):
@@ -957,7 +951,6 @@ def __getitem__(self, key):
957951
self.assertRaises(setonlyerror, exec, code,
958952
{'__builtins__': setonlydict({'superglobal': 1})})
959953

960-
@unittest.expectedFailure # TODO: RUSTPYTHON
961954
def test_exec_globals_dict_subclass(self):
962955
class customdict(dict): # this one should not do anything fancy
963956
pass
@@ -969,7 +962,6 @@ class customdict(dict): # this one should not do anything fancy
969962
self.assertRaisesRegex(NameError, "name 'superglobal' is not defined",
970963
exec, code, {'__builtins__': customdict()})
971964

972-
@unittest.expectedFailure # TODO: RUSTPYTHON; NameError: name 'superglobal' is not defined
973965
def test_eval_builtins_mapping(self):
974966
code = compile("superglobal", "test", "eval")
975967
# works correctly
@@ -1009,7 +1001,7 @@ def test_exec_redirected(self):
10091001
finally:
10101002
sys.stdout = savestdout
10111003

1012-
@unittest.expectedFailure # TODO: RUSTPYTHON
1004+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: Unexpected keyword argument closure
10131005
def test_exec_closure(self):
10141006
def function_without_closures():
10151007
return 3 * 5
@@ -1680,7 +1672,6 @@ def test_open(self):
16801672
self.assertRaises(ValueError, open, 'a\x00b')
16811673
self.assertRaises(ValueError, open, b'a\x00b')
16821674

1683-
@unittest.expectedFailure # TODO: RUSTPYTHON
16841675
@unittest.skipIf(sys.flags.utf8_mode, "utf-8 mode is enabled")
16851676
def test_open_default_encoding(self):
16861677
with EnvironmentVarGuard() as env:
@@ -2715,7 +2706,6 @@ def detach_readline(self):
27152706
else:
27162707
yield
27172708

2718-
@unittest.expectedFailure # TODO: RUSTPYTHON
27192709
def test_input_tty(self):
27202710
# Test input() functionality when wired to a tty
27212711
self.check_input_tty("prompt", b"quux")
@@ -2730,20 +2720,17 @@ def test_input_tty_non_ascii_unicode_errors(self):
27302720
# Check stdin/stdout error handler is used when invoking PyOS_Readline()
27312721
self.check_input_tty("prompté", b"quux\xe9", "ascii")
27322722

2733-
@unittest.expectedFailure # TODO: RUSTPYTHON
27342723
def test_input_tty_null_in_prompt(self):
27352724
self.check_input_tty("prompt\0", b"",
27362725
expected='ValueError: input: prompt string cannot contain '
27372726
'null characters')
27382727

2739-
@unittest.expectedFailure # TODO: RUSTPYTHON
27402728
def test_input_tty_nonencodable_prompt(self):
27412729
self.check_input_tty("prompté", b"quux", "ascii", stdout_errors='strict',
27422730
expected="UnicodeEncodeError: 'ascii' codec can't encode "
27432731
"character '\\xe9' in position 6: ordinal not in "
27442732
"range(128)")
27452733

2746-
@unittest.expectedFailure # TODO: RUSTPYTHON
27472734
def test_input_tty_nondecodable_input(self):
27482735
self.check_input_tty("prompt", b"quux\xe9", "ascii", stdin_errors='strict',
27492736
expected="UnicodeDecodeError: 'ascii' codec can't decode "
@@ -2960,7 +2947,7 @@ def test_type_qualname(self):
29602947
A.__qualname__ = b'B'
29612948
self.assertEqual(A.__qualname__, 'D.E')
29622949

2963-
@unittest.expectedFailure # TODO: RUSTPYTHON
2950+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '__firstlineno__' unexpectedly found in mappingproxy({'__firstlineno__': 42, '__module__': 'testmodule', '__dict__': <attribute '__dict__' of 'A' objects>, '__doc__': None})
29642951
def test_type_firstlineno(self):
29652952
A = type('A', (), {'__firstlineno__': 42})
29662953
self.assertEqual(A.__name__, 'A')
@@ -2972,7 +2959,7 @@ def test_type_firstlineno(self):
29722959
A.__firstlineno__ = 43
29732960
self.assertEqual(A.__dict__['__firstlineno__'], 43)
29742961

2975-
@unittest.expectedFailure # TODO: RUSTPYTHON
2962+
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: Expected type 'tuple' but 'str' found.
29762963
def test_type_typeparams(self):
29772964
class A[T]:
29782965
pass

Lib/test/test_funcattrs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ def test___globals__(self):
7676
self.cannot_set_attr(self.b, '__globals__', 2,
7777
(AttributeError, TypeError))
7878

79-
# TODO: RUSTPYTHON
80-
@unittest.expectedFailure
8179
def test___builtins__(self):
8280
self.assertIs(self.b.__builtins__, __builtins__)
8381
self.cannot_set_attr(self.b, '__builtins__', 2,

0 commit comments

Comments
 (0)