exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
15.15k stars 520 forks source link

error: syntax error, unexpected 'and' #323

Open starbugs-qurong opened 1 year ago

starbugs-qurong commented 1 year ago

I have run the following python program program3.py by codon.

class g32Ck29 (): l618xA2v = "IXgotDE13" JR2F7RH5o = "r" ZPs35284 = 0.5 vggx3vQ3 = 0.31 def Q0400A8 ( self , M1595y67A : int , Zxd3V4Yw : int , wxUjz87u : int ) -> bool : if (((self.l618xA2v)==None)and(self.JR2F7RH5o)==("V_J9S2w_UA")) : self.ZPs35284+=self.vggx3vQ3
if name == 'main': u3hZC2EfI = 2564 s05PK59Exs = 1522 PYMX80c = 7030 OAD7y28949= g32Ck29(); OAD7y28949.Q0400A8(u3hZC2EfI,s05PK59Exs,PYMX80c) print(OAD7y28949.ZPs35284)

And it output error message as follow: codon_program3.py:7:31: error: syntax error, unexpected 'and'

I hava run it by both python3 and pypy3 and output the following content: 0.5

The related files can be found in https://github.com/starbugs-qurong/python-compiler-test/tree/main/codon/python_3

elisbyberi commented 1 year ago

@starbugs-qurong Same as in #322, and you have to use type hint Optional[str], if class member l618xA2v is going to be None.

class g32Ck29:
    l618xA2v: Optional[str] = "IXgotDE13"
starbugs-qurong commented 1 year ago

Same as in #322 , spaces must be added before and after the keyword "and". I have roughly read the rules of Whitespace in Expressions and Statements in PEP 8 and didn't find the explanation of “or” and "and".

elisbyberi commented 1 year ago

@starbugs-qurong Duplicate of #317

elisbyberi commented 1 year ago

@starbugs-qurong See PEP 8 -> Whitespace in Expressions and Statements -> Other Recommendations.

Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).

inumanag commented 4 days ago

Duplicate of #321.