@@ -53,10 +53,12 @@ def parse(source, filename='<unknown>', mode='exec', *,
5353
5454def literal_eval (node_or_string ):
5555 """
56- Safely evaluate an expression node or a string containing a Python
56+ Evaluate an expression node or a string containing only a Python
5757 expression. The string or node provided may only consist of the following
5858 Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
5959 sets, booleans, and None.
60+
61+ Caution: A complex expression can overflow the C stack and cause a crash.
6062 """
6163 if isinstance (node_or_string , str ):
6264 node_or_string = parse (node_or_string .lstrip (" \t " ), mode = 'eval' )
@@ -234,6 +236,12 @@ def increment_lineno(node, n=1):
234236 location in a file.
235237 """
236238 for child in walk (node ):
239+ # TypeIgnore is a special case where lineno is not an attribute
240+ # but rather a field of the node itself.
241+ if isinstance (child , TypeIgnore ):
242+ child .lineno = getattr (child , 'lineno' , 0 ) + n
243+ continue
244+
237245 if 'lineno' in child ._attributes :
238246 child .lineno = getattr (child , 'lineno' , 0 ) + n
239247 if (
@@ -849,7 +857,7 @@ def visit_Import(self, node):
849857
850858 def visit_ImportFrom (self , node ):
851859 self .fill ("from " )
852- self .write ("." * node .level )
860+ self .write ("." * ( node .level or 0 ) )
853861 if node .module :
854862 self .write (node .module )
855863 self .write (" import " )
0 commit comments