FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update test_future.py from Cpython v3.11.2 by Masorubka1 · Pull Request #4830 · RustPython/RustPython · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
45 changes: 42 additions & 3 deletions Lib/test/test_future.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,12 @@ def _exec_future(self, code):
scope = {}
exec(
"from __future__ import annotations\n"
+ code, {}, scope
+ code, scope
)
return scope

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_annotations(self):
eq = self.assertAnnotationEqual
eq('...')
Expand Down Expand Up @@ -303,10 +305,11 @@ def test_annotations(self):
eq("list[str]")
eq("dict[str, int]")
eq("set[str,]")
eq("tuple[()]")
eq("tuple[str, ...]")
eq("tuple[(str, *types)]")
eq("tuple[str, *types]")
eq("tuple[str, int, (str, int)]")
eq("tuple[(*int, str, str, (str, int))]")
eq("tuple[*int, str, str, (str, int)]")
eq("tuple[str, int, float, dict[str, int]]")
eq("slice[0]")
eq("slice[0:1]")
Expand All @@ -321,6 +324,21 @@ def test_annotations(self):
eq("slice[1:2, 1]")
eq("slice[1:2, 2, 3]")
eq("slice[()]")
# Note that `slice[*Ts]`, `slice[*Ts,]`, and `slice[(*Ts,)]` all have
# the same AST, but only `slice[*Ts,]` passes this test, because that's
# what the unparser produces.
eq("slice[*Ts,]")
eq("slice[1, *Ts]")
eq("slice[*Ts, 2]")
eq("slice[1, *Ts, 2]")
eq("slice[*Ts, *Ts]")
eq("slice[1, *Ts, *Ts]")
eq("slice[*Ts, 1, *Ts]")
eq("slice[*Ts, *Ts, 1]")
eq("slice[1, *Ts, *Ts, 2]")
eq("slice[1:2, *Ts]")
eq("slice[*Ts, 1:2]")
eq("slice[1:2, *Ts, 3:4]")
eq("slice[a, b:c, d:e:f]")
eq("slice[(x for x in a)]")
eq('str or None if sys.version_info[0] > (3,) else str or bytes or None')
Expand Down Expand Up @@ -423,6 +441,27 @@ def foo():
def bar(arg: (yield)): pass
"""))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_get_type_hints_on_func_with_variadic_arg(self):
# `typing.get_type_hints` might break on a function with a variadic
# annotation (e.g. `f(*args: *Ts)`) if `from __future__ import
# annotations`, because it could try to evaluate `*Ts` as an expression,
# which on its own isn't value syntax.
namespace = self._exec_future(dedent("""\
class StarredC: pass
class C:
def __iter__(self):
yield StarredC()
c = C()
def f(*args: *c): pass
import typing
hints = typing.get_type_hints(f)
"""))

hints = namespace.pop('hints')
self.assertIsInstance(hints['args'], namespace['StarredC'])


if __name__ == "__main__":
unittest.main()

Back | FazBrowse Home | New Git URL