Duroktar / Wolf

Wolf is a VsCode extension that enables live inspection of Python code in the editor.
Other
128 stars 7 forks source link

wolf fails on pass #28

Closed Almenon closed 3 years ago

Almenon commented 6 years ago
def foo():
    pass # wolf outputs error: File "<string>", line 1

foo()
Almenon commented 6 years ago

it also fails on break

# test program copied from https://www.programiz.com/python-programming/examples/prime-number

num = 407

# take input from the user
# num = int(input("Enter a number: "))

# prime numbers are greater than 1
if num > 1:
   # check for factors
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break # <- FAILS HERE: File "<string>", line 1
   else:
       print(num,"is a prime number")

# if input number is less than
# or equal to 1, it is not prime
else:
   print(num,"is not a prime number")
Almenon commented 6 years ago

fails on continue too (see previous example, just replace break with continue)

Duroktar commented 6 years ago

Awesome! Okay man, I'm busy for the next bit but I'll have those fixed up soon as I can after.

Hmm, funny that pass and continue break it.. I've got a mighty cryptic regex that should just ignore those keywords..

Anyways, thanks for breaking em up too. Cheers :beers:

Almenon commented 6 years ago

yeah... the regex is so long it times out on regex101 XD

https://regex101.com/r/sf6nAH/15

BTW you can break regex up into multiple lines and add comments, like so:

import re

WOLF_MACROS = re.compile(r"""
\w # we want to capture word because bla bla bla
\d # then number because bla bla bla
""", re.VERBOSE) # verbose ignores comments and whitespace

(Trey Hunner gave a talk to SD python about this recently)

And at some point you probably want to break some of the regex logic out into functions or seperate it out into multiple regexes.