Skip to content
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.

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

debug reports indentation error inside of if-else blocks within __init__ #85

Closed
awray3 opened this issue Jun 30, 2021 · 2 comments
Closed

Comments

@awray3
Copy link

awray3 commented Jun 30, 2021

I noticed this strange behavior when using debug to debug some if-else blocks in my code. Here is a small script to recreate the bug.

# script.py
from devtools import debug

class Test:
    def __init__(self, flag: bool):
        if flag:
            debug('Flag was true')
        else:
            debug('Flag was false')

# instantiate this class with True flag
test = Test(flag=True)

Output of python script.py:

script.py:7 __init__ (error parsing code, IndentationError: unindent does not match any outer indentation level (script.py, line 3))
    'Flag was true' (str) len=13

There is no indentation error in the code, and furthermore, I notice that adding something benign after the debug statement makes this go away. For example, if instead script.py looks like this, there is no issue:

# script2.py
from devtools import debug


class Test:
    def __init__(self, flag):
        if flag:
            debug('Flag was true')
            print('This helps debug out for some reason.')
        else:
            debug('Flag was false')

test = Test(True)

Output of python script2.py (which I expect to happen normally):

script2.py:7 __init__
    'Flag was true' (str) len=13
This helps debug out for some reason.

Environment info: I tested this by creating a new conda environment with python 3.7.

$ conda --version
conda 4.10.1

$ python --version
python 3.7.10

$ pip list
Package    Version
---------- -------------------
certifi    2021.5.30
devtools   0.6.1
pip        21.1.3
setuptools 52.0.0.post20210125
wheel      0.36.2
@alexmojaki
Copy link
Contributor

Fixed in #82

@samuelcolvin
Copy link
Owner

fixed in #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants