Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-107015: Remove async_hacks from the tokenizer#107018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
pablogsal merged 3 commits intopython:mainfrompablogsal:gh-107015
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
fix tests
  • Loading branch information
@pablogsal
pablogsal committedJul 25, 2023
commita4830c5c76203aa551ca1da385042b21e94808fc
2 changes: 0 additions & 2 deletionsLib/keyword.py
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 1 addition & 1 deletionLib/test/test_peg_generator/test_c_parser.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -404,7 +404,7 @@ def test_ternary_operator(self) -> None:
a='[' b=NAME c=for_if_clauses d=']' { _PyAST_ListComp(b, c, EXTRA) }
)
for_if_clauses[asdl_comprehension_seq*]: (
a[asdl_comprehension_seq*]=(y=[ASYNC] 'for' a=NAME 'in' b=NAME c[asdl_expr_seq*]=('if' z=NAME { z })*
a[asdl_comprehension_seq*]=(y=['async'] 'for' a=NAME 'in' b=NAME c[asdl_expr_seq*]=('if' z=NAME { z })*
{ _PyAST_comprehension(_PyAST_Name(((expr_ty) a)->v.Name.id, Store, EXTRA), b, c, (y == NULL) ? 0 : 1, p->arena) })+ { a }
)
"""
Expand Down
68 changes: 34 additions & 34 deletionsLib/test/test_tokenize.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2521,7 +2521,7 @@ def test_tabs(self):
def test_async(self):

self.check_tokenize('async = 1', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
EQUAL '=' (1, 6) (1, 7)
NUMBER '1' (1, 8) (1, 9)
""")
Expand All@@ -2530,21 +2530,21 @@ def test_async(self):
NAME 'a' (1, 0) (1, 1)
EQUAL '=' (1, 2) (1, 3)
LPAR '(' (1, 4) (1, 5)
ASYNC 'async' (1, 5) (1, 10)
NAME 'async' (1, 5) (1, 10)
EQUAL '=' (1, 11) (1, 12)
NUMBER '1' (1, 13) (1, 14)
RPAR ')' (1, 14) (1, 15)
""")

self.check_tokenize('async()', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
LPAR '(' (1, 5) (1, 6)
RPAR ')' (1, 6) (1, 7)
""")

self.check_tokenize('class async(Bar):pass', """\
NAME 'class' (1, 0) (1, 5)
ASYNC 'async' (1, 6) (1, 11)
NAME 'async' (1, 6) (1, 11)
LPAR '(' (1, 11) (1, 12)
NAME 'Bar' (1, 12) (1, 15)
RPAR ')' (1, 15) (1, 16)
Expand All@@ -2554,25 +2554,25 @@ def test_async(self):

self.check_tokenize('class async:pass', """\
NAME 'class' (1, 0) (1, 5)
ASYNC 'async' (1, 6) (1, 11)
NAME 'async' (1, 6) (1, 11)
COLON ':' (1, 11) (1, 12)
NAME 'pass' (1, 12) (1, 16)
""")

self.check_tokenize('await = 1', """\
AWAIT 'await' (1, 0) (1, 5)
NAME 'await' (1, 0) (1, 5)
EQUAL '=' (1, 6) (1, 7)
NUMBER '1' (1, 8) (1, 9)
""")

self.check_tokenize('foo.async', """\
NAME 'foo' (1, 0) (1, 3)
DOT '.' (1, 3) (1, 4)
ASYNC 'async' (1, 4) (1, 9)
NAME 'async' (1, 4) (1, 9)
""")

self.check_tokenize('async for a in b: pass', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NAME 'for' (1, 6) (1, 9)
NAME 'a' (1, 10) (1, 11)
NAME 'in' (1, 12) (1, 14)
Expand All@@ -2582,7 +2582,7 @@ def test_async(self):
""")

self.check_tokenize('async with a as b: pass', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NAME 'with' (1, 6) (1, 10)
NAME 'a' (1, 11) (1, 12)
NAME 'as' (1, 13) (1, 15)
Expand All@@ -2592,45 +2592,45 @@ def test_async(self):
""")

self.check_tokenize('async.foo', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
DOT '.' (1, 5) (1, 6)
NAME 'foo' (1, 6) (1, 9)
""")

self.check_tokenize('async', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
""")

self.check_tokenize('async\n#comment\nawait', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NEWLINE '' (1, 5) (1, 5)
AWAIT 'await' (3, 0) (3, 5)
NAME 'await' (3, 0) (3, 5)
""")

self.check_tokenize('async\n...\nawait', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NEWLINE '' (1, 5) (1, 5)
ELLIPSIS '...' (2, 0) (2, 3)
NEWLINE '' (2, 3) (2, 3)
AWAIT 'await' (3, 0) (3, 5)
NAME 'await' (3, 0) (3, 5)
""")

self.check_tokenize('async\nawait', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NEWLINE '' (1, 5) (1, 5)
AWAIT 'await' (2, 0) (2, 5)
NAME 'await' (2, 0) (2, 5)
""")

self.check_tokenize('foo.async + 1', """\
NAME 'foo' (1, 0) (1, 3)
DOT '.' (1, 3) (1, 4)
ASYNC 'async' (1, 4) (1, 9)
NAME 'async' (1, 4) (1, 9)
PLUS '+' (1, 10) (1, 11)
NUMBER '1' (1, 12) (1, 13)
""")

self.check_tokenize('async def foo(): pass', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NAME 'def' (1, 6) (1, 9)
NAME 'foo' (1, 10) (1, 13)
LPAR '(' (1, 13) (1, 14)
Expand All@@ -2647,7 +2647,7 @@ def foo(await):
await
async += 1
''', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NAME 'def' (1, 6) (1, 9)
NAME 'foo' (1, 10) (1, 13)
LPAR '(' (1, 13) (1, 14)
Expand All@@ -2658,12 +2658,12 @@ def foo(await):
NAME 'def' (2, 2) (2, 5)
NAME 'foo' (2, 6) (2, 9)
LPAR '(' (2, 9) (2, 10)
AWAIT 'await' (2, 10) (2, 15)
NAME 'await' (2, 10) (2, 15)
RPAR ')' (2, 15) (2, 16)
COLON ':' (2, 16) (2, 17)
NEWLINE '' (2, 17) (2, 17)
INDENT '' (3, -1) (3, -1)
AWAIT 'await' (3, 4) (3, 9)
NAME 'await' (3, 4) (3, 9)
EQUAL '=' (3, 10) (3, 11)
NUMBER '1' (3, 12) (3, 13)
NEWLINE '' (3, 13) (3, 13)
Expand All@@ -2673,26 +2673,26 @@ def foo(await):
COLON ':' (4, 6) (4, 7)
NEWLINE '' (4, 7) (4, 7)
INDENT '' (5, -1) (5, -1)
AWAIT 'await' (5, 4) (5, 9)
NAME 'await' (5, 4) (5, 9)
NEWLINE '' (5, 9) (5, 9)
DEDENT '' (6, -1) (6, -1)
DEDENT '' (6, -1) (6, -1)
ASYNC 'async' (6, 0) (6, 5)
NAME 'async' (6, 0) (6, 5)
PLUSEQUAL '+=' (6, 6) (6, 8)
NUMBER '1' (6, 9) (6, 10)
NEWLINE '' (6, 10) (6, 10)
""")

self.check_tokenize('async def foo():\n async for i in 1: pass', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NAME 'def' (1, 6) (1, 9)
NAME 'foo' (1, 10) (1, 13)
LPAR '(' (1, 13) (1, 14)
RPAR ')' (1, 14) (1, 15)
COLON ':' (1, 15) (1, 16)
NEWLINE '' (1, 16) (1, 16)
INDENT '' (2, -1) (2, -1)
ASYNC 'async' (2, 2) (2, 7)
NAME 'async' (2, 2) (2, 7)
NAME 'for' (2, 8) (2, 11)
NAME 'i' (2, 12) (2, 13)
NAME 'in' (2, 14) (2, 16)
Expand All@@ -2703,14 +2703,14 @@ def foo(await):
""")

self.check_tokenize('async def foo(async): await', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NAME 'def' (1, 6) (1, 9)
NAME 'foo' (1, 10) (1, 13)
LPAR '(' (1, 13) (1, 14)
ASYNC 'async' (1, 14) (1, 19)
NAME 'async' (1, 14) (1, 19)
RPAR ')' (1, 19) (1, 20)
COLON ':' (1, 20) (1, 21)
AWAIT 'await' (1, 22) (1, 27)
NAME 'await' (1, 22) (1, 27)
""")

self.check_tokenize('''\
Expand All@@ -2734,15 +2734,15 @@ async def bar(): pass
COLON ':' (3, 11) (3, 12)
NAME 'pass' (3, 13) (3, 17)
NEWLINE '' (3, 17) (3, 17)
ASYNC 'async' (4, 2) (4, 7)
NAME 'async' (4, 2) (4, 7)
NAME 'def' (4, 8) (4, 11)
NAME 'bar' (4, 12) (4, 15)
LPAR '(' (4, 15) (4, 16)
RPAR ')' (4, 16) (4, 17)
COLON ':' (4, 17) (4, 18)
NAME 'pass' (4, 19) (4, 23)
NEWLINE '' (4, 23) (4, 23)
AWAIT 'await' (6, 2) (6, 7)
NAME 'await' (6, 2) (6, 7)
EQUAL '=' (6, 8) (6, 9)
NUMBER '2' (6, 10) (6, 11)
DEDENT '' (6, -1) (6, -1)
Expand All@@ -2755,7 +2755,7 @@ def baz(): pass
async def bar(): pass

await = 2''', """\
ASYNC 'async' (1, 0) (1, 5)
NAME 'async' (1, 0) (1, 5)
NAME 'def' (1, 6) (1, 9)
NAME 'f' (1, 10) (1, 11)
LPAR '(' (1, 11) (1, 12)
Expand All@@ -2770,15 +2770,15 @@ async def bar(): pass
COLON ':' (3, 11) (3, 12)
NAME 'pass' (3, 13) (3, 17)
NEWLINE '' (3, 17) (3, 17)
ASYNC 'async' (4, 2) (4, 7)
NAME 'async' (4, 2) (4, 7)
NAME 'def' (4, 8) (4, 11)
NAME 'bar' (4, 12) (4, 15)
LPAR '(' (4, 15) (4, 16)
RPAR ')' (4, 16) (4, 17)
COLON ':' (4, 17) (4, 18)
NAME 'pass' (4, 19) (4, 23)
NEWLINE '' (4, 23) (4, 23)
AWAIT 'await' (6, 2) (6, 7)
NAME 'await' (6, 2) (6, 7)
EQUAL '=' (6, 8) (6, 9)
NUMBER '2' (6, 10) (6, 11)
DEDENT '' (6, -1) (6, -1)
Expand Down
4 changes: 2 additions & 2 deletionsLib/test/test_type_comments.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -260,8 +260,8 @@ def test_asyncdef(self):
self.assertEqual(tree.body[1].type_comment, None)

def test_asyncvar(self):
for tree inself.parse_all(asyncvar, maxver=6):
pass
withself.assertRaises(SyntaxError):
self.classic_parse(asyncvar)

def test_asynccomp(self):
for tree in self.parse_all(asynccomp, minver=6):
Expand Down
5 changes: 1 addition & 4 deletionsTools/peg_generator/pegen/keywordgen.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,9 +35,6 @@
issoftkeyword = frozenset(softkwlist).__contains__
'''.lstrip()

EXTRA_KEYWORDS = ["async", "await"]


def main() -> None:
parser = argparse.ArgumentParser(
description="Generate the Lib/keywords.py file from the grammar."
Expand All@@ -62,7 +59,7 @@ def main() -> None:
gen.collect_rules()

with args.keyword_file as thefile:
all_keywords = sorted(list(gen.keywords.keys()) + EXTRA_KEYWORDS)
all_keywords = sorted(list(gen.keywords.keys()))
all_soft_keywords = sorted(gen.soft_keywords)

keywords = "" if not all_keywords else " " + ",\n ".join(map(repr, all_keywords))
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp