mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Fix an issue with assigning to __debug__, which is essentially the same as assigning to a keyword.
This commit is contained in:
@@ -97,6 +97,7 @@ class Context(object):
|
|||||||
self.node = node
|
self.node = node
|
||||||
self.blocks = []
|
self.blocks = []
|
||||||
self.parent_context = parent_context
|
self.parent_context = parent_context
|
||||||
|
self.used_names = dict()
|
||||||
|
|
||||||
def is_async_funcdef(self):
|
def is_async_funcdef(self):
|
||||||
# Stupidly enough async funcdefs can have two different forms,
|
# Stupidly enough async funcdefs can have two different forms,
|
||||||
@@ -387,6 +388,10 @@ class ErrorFinder(Normalizer):
|
|||||||
self._add_indentation_error(message, spacing)
|
self._add_indentation_error(message, spacing)
|
||||||
else:
|
else:
|
||||||
self._add_syntax_error('invalid syntax', leaf)
|
self._add_syntax_error('invalid syntax', leaf)
|
||||||
|
elif leaf.type == 'name':
|
||||||
|
if leaf.value == '__debug__' and leaf.is_definition():
|
||||||
|
message = 'assignment to keyword'
|
||||||
|
self._add_syntax_error(message, leaf)
|
||||||
elif leaf.type == 'string':
|
elif leaf.type == 'string':
|
||||||
if 'b' in leaf.string_prefix.lower() \
|
if 'b' in leaf.string_prefix.lower() \
|
||||||
and any(c for c in leaf.value if ord(c) > 127):
|
and any(c for c in leaf.value if ord(c) > 127):
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ def test_indentation_errors(code, positions):
|
|||||||
'from .__future__ import whatever',
|
'from .__future__ import whatever',
|
||||||
'def f(x=3, y): pass',
|
'def f(x=3, y): pass',
|
||||||
'lambda x=3, y: x',
|
'lambda x=3, y: x',
|
||||||
#'__debug__ = 1'
|
'__debug__ = 1',
|
||||||
|
'with x() as __debug__: pass',
|
||||||
# Mostly 3.6 relevant
|
# Mostly 3.6 relevant
|
||||||
'[]: int',
|
'[]: int',
|
||||||
'[a, b]: int',
|
'[a, b]: int',
|
||||||
|
|||||||
Reference in New Issue
Block a user