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

Use more pythonic syntax with enums #1878

Closed
Shadowblitz16 opened this issue Nov 23, 2020 · 6 comments
Closed

Use more pythonic syntax with enums #1878

Shadowblitz16 opened this issue Nov 23, 2020 · 6 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Nov 23, 2020

Describe the project you are working on:
NetworkingTest

Describe the problem or limitation you are having in your project:
Enums and Consts are basicly the same thing but they use a odd syntax for gdscript and enums and const are written diffrently
Realized const enums are actually dictionaries Xd

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Change enums and consts so they use this syntax

#valid
enum MyEnum:
    ValueA = someConstValue,  #valid
    ValueB = someNonConstValue,   #valid
    ValueC : someConstValue, #invalid
    ValueD : someNonConstValue,   #invalid

#invalid
enum MyEnum {
}

#invalid
enum MyEnum = {
}

It would not only be a cleaner look

EDIT

I want to mention the reason I suggest '=' or : is to be easier to understand : is more of a scope or inheritance thing and = is more of a assignment thing

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Above

If this enhancement will not be used often, can it be worked around with a few lines of script?:
This would not only be more pythonic but its more consistent.

Is there a reason why this should be core and not an add-on in the asset library?:
enums and consts already are this would just make syntax more consistent

@Calinou
Copy link
Member

Calinou commented Nov 23, 2020

Python has neither enums nor constants in the core language 🙂

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Nov 23, 2020

@Calinou yes i know but I think the : syntax for blocks is more pythonic.

Also unlike arrays and dictionaries, enums and consts enums are more of a scope then a object or variable

@Shadowblitz16 Shadowblitz16 changed the title Use more pythonic syntax with enums and consts Use more pythonic syntax with enums Nov 24, 2020
@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Nov 24, 2020

@aaronfranke
@dalexeev

I just realized const enums are actually const dictionaries
I edited the issue

@Calinou
Copy link
Member

Calinou commented Jun 6, 2021

Closing due to lack of support (see reactions on OP and the lack of activity here).

@dalexeev
Copy link
Member

In fact, the proposal is not very clear, this is its main problem. The main point of this proposal is

enum MyEnum:
    MY_VALUE_1,
    MY_VALUE_2,
    MY_VALUE_3,

instead of

enum MyEnum {
    MY_VALUE_1,
    MY_VALUE_2,
    MY_VALUE_3,
}

This is a cosmetic change and I am not against it. I admit, in this case, I got excited.

Saving one line is not that important, but it really looks more consistent. An enumeration, unlike an array/dictionary, is a definition, not a value literal, so it is ok that the syntax is different. Moreover, in 4.0-dev named enums are no longer dictionaries.

@Calinou, I suggest reopen it. The lack of support in this case is not so obvious. At least, it should be given a second chance.
@Shadowblitz16, please correct the OP to be clearer.

@Calinou
Copy link
Member

Calinou commented Sep 29, 2021

@dalexeev Feel free to open a new proposal for this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants