2

I have some code with a variable named "angle". However in the loop I mistakenly wrote "angla".

My question is, how might I make VS code warn me about this? Some IDEs, like PyCharm, warn me of the mistake.

... 
for line in open("data.txt", "r"):
    ...
    angle_a = atan2(Vya, Vxa)
    angle_b = atan2(Vyb, Vxb)
    while t <= 10:
        Pa, Va_mag, angle_a, Va = motion(
            Pa, Va_mag, angle_a, Va)  
        Pb, Vb_mag, angle_b, Vb = motion(
            Pb, Vb_mag, angle_b, Vb)  
        if collision_test(Pa, Pb) == True: 
            Va, Vb = after_collision_velocity(Va, Vb, Pa, Pb)
            Va_mag = vec_magnitude(Va)  
            Vb_mag = vec_magnitude(Vb)
            angla_a = atan2(Va[1], Va[0]) # here is the mistake
            angle_b = atan2(Vb[1], Vb[0])
        t += dt 
...

Is there any way VS code could give me an error when something like this happens? Any helpful extensions, spell-checkers, AI-IntelliSense, etc? (Python-specific)

5
  • If there are lots of other errors/warnings in the code, this might be related to stackoverflow.com/questions/51861276/… Commented Aug 16, 2019 at 17:51
  • There was no other error. Commented Aug 16, 2019 at 17:56
  • First ask yourself this question - how do you presume VS code to know angla_a is a typo of angle_a and not a new object as your code indicates? Consider this - should VS code also warn you when you introduce angle_c like "did you mean angle_b?" IMO unfortunately this is one of those scenarios you just need to be careful, because it is a valid syntax, just creating a new object. Commented Aug 16, 2019 at 19:24
  • @Roca it gives an error in PyCharm Commented Aug 16, 2019 at 19:46
  • It wouldn't give you an error if it were angel_a. It's just a spelling check, which there are plenty spell checker extension on the VS Code extension market. But if you actually wanted to check for objects being referenced correctly that's a different story. Commented Aug 16, 2019 at 19:52

1 Answer 1

1

Visual Studio Code's marketplace has extensions that may help you preemptively identify these types of errors.

I am not sure about post-error detection, but Microsoft's Visual Studio IntelliCode will suggest the correct variable names before you begin making a typing mistake.

Visual Studio IntelliCode

There is also a Python-specific extension at:

Python Extension - With IntelliSense

IntelliSense In Action:

IntelliSense ScreenShot

Sign up to request clarification or add additional context in comments.

3 Comments

After installing the extensions (try both), make sure to restart your VS Code client. I have added a screenshot of IntelliSense suggesting the correct variable declaration.
I see now. That is open.. indeed. But suppose you even made a typo in that condition
Right, IntelliSense just tries to help you avoid the mistake. I'm not sure you could detect the typo in your situation, especially because it looks like any other variable declaration. Maybe, if you suspect a typo, try using ctrl+f (find all) to investigate the situation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.