nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.52k stars 130 forks source link

Incorrect SyntaxError report? #536

Closed bburan closed 7 months ago

bburan commented 7 months ago

The following code:

from enaml.widgets.api import Action, MainWindow, Menu, MenuBar

enamldef Main(MainWindow):
    MenuBar:
        Menu:
            title = 'Demo'
            Action:
                text = 'Demo Action'
                triggered:
                    try:
                        pass
                    except Exception as e:
                        pass

Gives the following:

  File "...\Lib\site-packages\enaml\core\parser\base_python_parser.py", line 451, in raise_raw_syntax_error
    raise self._build_syntax_error(message, start, end)
  File "test.enaml", line 12
    try:
    ^^^
SyntaxError: invalid syntax

I can't decide if this is correct or if it should point to line 11 (triggered:) instead? I guess it depends on whether the parser is trying to treat triggered as an object rather than an notification binding?

This is on 0.17.0.

sccolbert commented 7 months ago

Its probably treating “triggered:” as an object since the rule is not case sensitive. We only uppercase by convention.

On Mon, Nov 20, 2023 at 18:09 Brad Buran @.***> wrote:

The following code:

from enaml.widgets.api import Action, MainWindow, Menu, MenuBar

enamldef Main(MainWindow): MenuBar: Menu: title = 'Demo' Action: text = 'Demo Action' triggered: try: pass except Exception as e: pass

Gives the following:

File "...\Lib\site-packages\enaml\core\parser\base_python_parser.py", line 451, in raise_raw_syntax_error raise self._build_syntax_error(message, start, end) File "test.enaml", line 12 try: ^^^ SyntaxError: invalid syntax

I can't decide if this is correct or if it should point to line 11 ( triggered:) instead? I guess it depends on whether the parser is trying to treat triggered as an object rather than an notification binding?

— Reply to this email directly, view it on GitHub https://github.com/nucleic/enaml/issues/536, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABBQSPK3Q2UNB2T63TLKCLYFPWNDAVCNFSM6AAAAAA7TWNV3GVHI2DSMVQWIX3LMV43ASLTON2WKOZSGAYDGMRSGMYTGNQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

MatthieuDartiailh commented 7 months ago

Python blocks inside operator are parsed as regular Python code and no special effort is made to link it back to enaml operators.

It may be possible but it would require to deviate further from pegen version.

bburan commented 7 months ago

Closing since it is likely not worth the effort.