[proxy] github.com← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

bpo-37757: Disallow PEP 572 cases that expose implementation details by ncoghlan · Pull Request #15131 · python/cpython

ncoghlan

- comprehension iteration variables are explicitly local, but
  named expression targets in comprehensions are nonlocal or
  global. Raise TargetScopeError as specified in PEP 572
- named expression targets in the outermost iterable of a
  comprehension have an ambiguous target scope. Avoid resolving
  that question now by raising TargetScopeError. PEP 572
  explicitly requires this for cases where the bound name
  conflicts with the iteration variable in the comprehension,
  but CPython can't easily restrict the exception to that case
  (as it doesn't know the target variable names when visiting
  the outermost iterator expression)

ncoghlan changed the title Bug #37757: Raise TargetScopeError as specified in PEP 572 bpo-37757: Raise TargetScopeError as specified in PEP 572

Aug 5, 2019

Merged

ncoghlan changed the title bpo-37757: Raise TargetScopeError as specified in PEP 572 bpo-37757: Disallow PEP 572 cases that expose implementation details

Aug 9, 2019

- use the public "assignment expression" name rather than the
  internal "named expression" one
- mention the variable name when the conflict is related to
  the exact name rather than the code structure
- don't pass the variable name when the exception message
  doesn't need it

ncoghlan deleted the bpo-37757-targetscopeerror-for-iteration-variable-conflicts branch

August 25, 2019 13:45

ncoghlan added a commit to ncoghlan/cpython that referenced this pull request

Aug 25, 2019

…ythonGH-15131)

- drop TargetScopeError in favour of raising SyntaxError directly
  as per the updated PEP 572
- comprehension iteration variables are explicitly local, but
  named expression targets in comprehensions are nonlocal or
  global. Raise SyntaxError as specified in PEP 572
- named expression targets in the outermost iterable of a
  comprehension have an ambiguous target scope. Avoid resolving
  that question now by raising SyntaxError. PEP 572
  originally required this only for cases where the bound name
  conflicts with the iteration variable in the comprehension,
  but CPython can't easily restrict the exception to that case
  (as it doesn't know the target variable names when visiting
  the outermost iterator expression)

(cherry picked from commit 5dbe0f5)

lisroach pushed a commit to lisroach/cpython that referenced this pull request

Sep 10, 2019
…ythonGH-15131)

- drop TargetScopeError in favour of raising SyntaxError directly
  as per the updated PEP 572
- comprehension iteration variables are explicitly local, but
  named expression targets in comprehensions are nonlocal or
  global. Raise SyntaxError as specified in PEP 572
- named expression targets in the outermost iterable of a
  comprehension have an ambiguous target scope. Avoid resolving
  that question now by raising SyntaxError. PEP 572
  originally required this only for cases where the bound name
  conflicts with the iteration variable in the comprehension,
  but CPython can't easily restrict the exception to that case
  (as it doesn't know the target variable names when visiting
  the outermost iterator expression)

DinoV pushed a commit to DinoV/cpython that referenced this pull request

Jan 14, 2020
…ythonGH-15131)

- drop TargetScopeError in favour of raising SyntaxError directly
  as per the updated PEP 572
- comprehension iteration variables are explicitly local, but
  named expression targets in comprehensions are nonlocal or
  global. Raise SyntaxError as specified in PEP 572
- named expression targets in the outermost iterable of a
  comprehension have an ambiguous target scope. Avoid resolving
  that question now by raising SyntaxError. PEP 572
  originally required this only for cases where the bound name
  conflicts with the iteration variable in the comprehension,
  but CPython can't easily restrict the exception to that case
  (as it doesn't know the target variable names when visiting
  the outermost iterator expression)

websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request

Jul 20, 2020
…ythonGH-15131)

- drop TargetScopeError in favour of raising SyntaxError directly
  as per the updated PEP 572
- comprehension iteration variables are explicitly local, but
  named expression targets in comprehensions are nonlocal or
  global. Raise SyntaxError as specified in PEP 572
- named expression targets in the outermost iterable of a
  comprehension have an ambiguous target scope. Avoid resolving
  that question now by raising SyntaxError. PEP 572
  originally required this only for cases where the bound name
  conflicts with the iteration variable in the comprehension,
  but CPython can't easily restrict the exception to that case
  (as it doesn't know the target variable names when visiting
  the outermost iterator expression)