question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

in keyword in class method causes indentation problem

See original GitHub issue

Description

Class with a function named “in” causes indentation issue:

Input

The code looked like this before beautification:

class {
  get a() {

  }

  in () {

  }

  b () {

  }
}

Expected Output

The code should have looked like this after beautification:

(should be unchanged)

Actual Output

The code actually looked like this after beautification:

class {
    get a() {

        }

        in () {

        }

    b() {

    }
}

Steps to Reproduce

Tried on https://beautifier.io/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kcamsanccommented, Mar 24, 2022

If so, what’s the best way to reproduce this error in the Python implementation after forking and cloning the repo locally? Thanks.

I believe I figured out the answer to my question above.

I am now working on this change. I will keep you all updated on my progress!

0reactions
kcamsanccommented, Mar 30, 2022

Did you run make all? I’d be very surprised if that didn’t generate the test for both js and python, and result in a failure in the python test run.

Yes, to test this, I reverted my changes to tokenizer.py and ran both make and make all (not sure if there’s a difference there). Neither resulted in a failure, and within the make all output, I do see:

...
Test unpack() function. ... ok
test_detect (jsbeautifier.unpackers.tests.testurlencode.TestUrlencode)
Test detect() function. ... ok
test_unpack (jsbeautifier.unpackers.tests.testurlencode.TestUrlencode)
Test unpack function. ... ok

----------------------------------------------------------------------
Ran 36 tests in 0.056s

which I think means that no Python tests failed even after I reverted my changes in tokenizer.py. I also ran make py, which resulted in “PASSED”.

Looking into this further, I can actually see that my unit tests were automatically generated inpython/jsbeautifier/tests/generated/tests.py like you said, so I feel like it’s strange that no Python tests failed. FWIW, I know the JavaScript unit tests I wrote failed before I made changes to the JavaScript implementation.

I know I can’t make changes to python/jsbeautifier/tests/generated/tests.py as it is automatically generated. So, what’s the best way to write good unit tests to make sure this bug doesn’t reoccur in the future? (For now, like I mentioned, I’ve just had to run ./tools/python-dev js-beautify on a local .js file I made to see if the bug is still present in the Python implementation.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Having trouble with class methods - python - Stack Overflow
Based on your indention, you're defining your methods in your init method. Unindent them so they're the same level as your init method...
Read more >
Indentation Error in Python | How to Solve it - Edureka
As mentioned in the introduction paragraph, one of the main reasons for the indentation error is the absence of tabs and or whitespaces...
Read more >
How does Indentation Error Work in Python? - eduCBA
It happens mainly because of the absence of tabs and whitespaces between the lines of code. If there are any missing spaces between...
Read more >
How to fix indentation Error in Python - Numpy Ninja
Below are some of the common causes of an indentation error in Python: While coding you are using both the tab as well...
Read more >
Indentation - Washington
has 1 level of indentation, a loop in a method in a class has 2 levels of ... implementation details makes it difficult...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found