custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

Match statement #479

Closed stefanuytterhoeven closed 1 year ago

stefanuytterhoeven commented 1 year ago

first of all, I'm no expert in Python.

but, from what I've read, the match/case statement should be supported as of version 3.10 of python.

In HA, we are at 3.11 now. When retrieving the python version in pyscript it says 3.11

So, when I try to use match/case like

testvar='value'
match testvar:
     case 'value': 
          pass
      case _: 
          pass

this gives me error: NotImplementedError: ..... not implemented ast ast_match

craigbarratt commented 1 year ago

Pyscript implements a python interpreter using async methods. I wasn't aware this language feature was added, so I'll need to add support for it.

craigbarratt commented 1 year ago

I reviewed PEP 636 and it looks quite difficult to implement in the pyscript interpreter. So I'm not planning to support this.

I'd recommend putting your match code in a function with the @pyscript_compile decorator. That way you'll have access to full native Python functionality inside that function.

stefanuytterhoeven commented 1 year ago

Thx!

ALERTua commented 1 year ago

@stefanuytterhoeven could you please update or close the issue? Thank you

stefanuytterhoeven commented 1 year ago

Solved