Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial enamldef const storage #546

Closed
wants to merge 1 commit into from

Conversation

frmdstryr
Copy link
Contributor

@frmdstryr frmdstryr commented Mar 23, 2024

This makes the parser allow a "const" in an enamldef or child def that uses atom's ReadOnly member so it cannot be changed after the initial value is set. The only other difference from an attr is that the parser requires a default expression.

The existing parser (pegen not the ply one) actually allows "const" in an enamldef but not in a child def but throws an error because the visitor is not implemented in the block compiler.

I copied a lot of code in the gen_const_expr, idk if that can/should be cleaned up. It's mainly an inlined gen_storage_expr and gen_operator_expr.

An example use case...

from enaml.widgets.api import Window, Container, Label, PushButton

enamldef Main(Window): window:
    const locked: bool = True
    Container:
        Label:
            text = "Locked" if locked else "Unlocked"
        PushButton:
            text = "Try to unlock"
            clicked ::
                try:
                    window.locked = False
                except TypeError:
                    print("Nope!")

Any feedback is welcome.

Copy link

codecov bot commented Mar 23, 2024

Codecov Report

Merging #546 (a537128) into main (bf0ea6f) will increase coverage by 0.05%.
The diff coverage is 97.50%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #546      +/-   ##
==========================================
+ Coverage   70.74%   70.79%   +0.05%     
==========================================
  Files         287      287              
  Lines       25634    25673      +39     
  Branches     4676     4683       +7     
==========================================
+ Hits        18135    18176      +41     
+ Misses       6386     6385       -1     
+ Partials     1113     1112       -1     

@sccolbert
Copy link
Member

sccolbert commented Mar 24, 2024 via email

@frmdstryr frmdstryr closed this Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants