nucleic / enaml

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

Feature request: Allow const in enamldefs that uses the `ReadOnly` member #545

Closed frmdstryr closed 3 months ago

frmdstryr commented 4 months ago

It would be nice to be able use const instead of a normal attr that uses a Constant member so the value can't be changed from the initial value.

If you think this would be ok, I'd be willing to submit a PR.

MatthieuDartiailh commented 4 months ago

I will have to check how const is currently used. I am on my phone and could not remember/find what we do with it.

sccolbert commented 4 months ago

“const” is part of the templating system.

On Wed, Mar 6, 2024 at 12:38 Matthieu Dartiailh @.***> wrote:

I will have to check how const is currently used. I am on my phone and could not remember/find what we do with it.

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

MatthieuDartiailh commented 4 months ago

I know it has been a long time but could you explain a bit the reasoning behind const in template. Looking at the advanced example it get it serves to generate temporary bindings within the template body but is it all there is to it ?

Personally, I would not be against allowing const in enamldef with a different meaning from the one it takes in templates. And I should try to document templates because even to me there are obscure.

sccolbert commented 3 months ago

Yes, it has a purpose.

IIRC it is used to indicate expressions that are only evaluated once on the first invocation of the template, and they cannot be changed later. Those const values can then be used as parameters to specialize templates via template overrides/specialization, very similar to C++.

You cannot pass a non-type, or non-const parameter to a template.

On Mon, Mar 18, 2024 at 12:13 Matthieu Dartiailh @.***> wrote:

I know it has been a long time but could you explain a bit the reasoning behind const in template. Looking at the advanced example it get it serves to generate temporary bindings within the template body but is it all there is to it ?

Personally, I would not be against allowing const in enamldef with a different meaning from the one it takes in templates. And I should try to document templates because even to me there are obscure.

— Reply to this email directly, view it on GitHub https://github.com/nucleic/enaml/issues/545#issuecomment-2004492836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABBQSJBPPBSOINAKIMDBRTYY4OEJAVCNFSM6AAAAABEJJXQPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBUGQ4TEOBTGY . You are receiving this because you commented.Message ID: @.***>

sccolbert commented 3 months ago

**first unique* invocation of the template.

Template results are/should be cached based on their unique argument hash.

On Fri, Mar 22, 2024 at 18:25 Chris Colbert @.***> wrote:

Yes, it has a purpose.

IIRC it is used to indicate expressions that are only evaluated once on the first invocation of the template, and they cannot be changed later. Those const values can then be used as parameters to specialize templates via template overrides/specialization, very similar to C++.

You cannot pass a non-type, or non-const parameter to a template.

On Mon, Mar 18, 2024 at 12:13 Matthieu Dartiailh @.***> wrote:

I know it has been a long time but could you explain a bit the reasoning behind const in template. Looking at the advanced example it get it serves to generate temporary bindings within the template body but is it all there is to it ?

Personally, I would not be against allowing const in enamldef with a different meaning from the one it takes in templates. And I should try to document templates because even to me there are obscure.

— Reply to this email directly, view it on GitHub https://github.com/nucleic/enaml/issues/545#issuecomment-2004492836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABBQSJBPPBSOINAKIMDBRTYY4OEJAVCNFSM6AAAAABEJJXQPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBUGQ4TEOBTGY . You are receiving this because you commented.Message ID: @.***>