-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Closed
Labels
Description
Description
Code that is accepted by the python interpreter raises when fed through textwrap.dedent
Steps to Reproduce
- Create
is_generator_bug.pywith the content below (which I simplified from theis_generator_with_return_valuemethod body - Run
python is_generator_bug.py - Observe the kaboom
import ast
import inspect
from textwrap import dedent
class Bob:
def doit(self):
"""
this line is flush left
"""
if True:
yield 1234
if __name__ == '__main__':
b = Bob()
c = b.doit
if inspect.isgeneratorfunction(c):
tree = ast.parse(dedent(inspect.getsource(c)))Expected behavior: [What you expect to happen]
No Error
Actual behavior: [What actually happens]
$ python3.7 is_generator_bug.py
Traceback (most recent call last):
File "is_generator_bug.py", line 16, in <module>
tree = ast.parse(dedent(inspect.getsource(c)))
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
def doit(self):
^
IndentationError: unexpected indentReproduces how often: [What percentage of the time does it reproduce?]
100%
Versions
Scrapy : 2.0.1
lxml : 4.5.0.0
libxml2 : 2.9.10
cssselect : 1.1.0
parsel : 1.5.2
w3lib : 1.21.0
Twisted : 20.3.0
Python : 3.7.7 (default, Mar 11 2020, 23:30:22) - [Clang 10.0.0 (clang-1000.11.45.5)]
pyOpenSSL : 19.1.0 (OpenSSL 1.1.1d 10 Sep 2019)
cryptography : 2.8
Platform : Darwin-17.7.0-x86_64-i386-64bit