GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-45834: Move runtime 'except:' check to the parser by pablogsal · Pull Request #29625 · python/cpython

bpo-45834: Move runtime 'except:' check to the parser #29625

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.

Sign up for GitHub

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

Already on GitHub? Sign in to your account

Closed
pablogsal wants to merge 1 commit into python:main from pablogsal:bpo-45834

Uh oh!

There was an error while loading. Please reload this page.

Closed

bpo-45834: Move runtime 'except:' check to the parser #29625

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
78234d2
bpo-45834: Move runtime 'except:' check to the parser
pablogsal Nov 18, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

13 changes: 11 additions & 2 deletions 13 Grammar/python.gram
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,12 @@ with_item[withitem_ty]:
try_stmt[stmt_ty]:
| invalid_try_stmt
| 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) }
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) }
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ d_ex[asdl_match_case_seq*]=[default_except_block] el=[else_block] f=[finally_block] {
_PyAST_Try(b, (d_ex) ? (asdl_excepthandler_seq*)_PyPegen_seq_append_to_end(p, (asdl_seq*)ex, d_ex) : ex, el, f, EXTRA)
}
| 'try' &&':' b=block d_ex[asdl_match_case_seq*]=default_except_block el=[else_block] f=[finally_block] {
_PyAST_Try(b, (asdl_excepthandler_seq*)_PyPegen_singleton_seq(p, d_ex), el, f, EXTRA)
}

# Except statement
# ----------------
Expand All @@ -411,8 +416,9 @@ except_block[excepthandler_ty]:
| invalid_except_stmt_indent
| 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
| invalid_except_stmt
default_except_block[excepthandler_ty]:
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
finally_block[asdl_stmt_seq*]:
| invalid_finally_stmt
| 'finally' &&':' a=block { a }
Expand Down Expand Up @@ -1187,6 +1193,9 @@ invalid_try_stmt:
| a='try' ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
| 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
| 'try' ':' block except_block* a=default_except_block (except_block|default_except_block)+ {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "default 'except:' must be last") }

invalid_except_stmt:
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
Expand Down
43 changes: 43 additions & 0 deletions 43 Lib/test/test_syntax.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,49 @@
Traceback (most recent call last):
IndentationError: expected an indented block after 'finally' statement on line 5

>>> try:
... something()
... except:
... pass
... except A:
... pass
... else:
... pass
... finally:
... pass
Traceback (most recent call last):
SyntaxError: default 'except:' must be last

>>> try:
... something()
... except:
... pass
... except:
... pass
... else:
... pass
... finally:
... pass
Traceback (most recent call last):
SyntaxError: default 'except:' must be last
Comment thread
pablogsal marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


>>> try:
... something()
... except A:
... pass
... except B:
... pass
... except:
... pass
... except C:
... pass
... else:
... pass
... finally:
... pass
Traceback (most recent call last):
SyntaxError: default 'except:' must be last

>>> with A:
... pass
Traceback (most recent call last):
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.