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

Enumerant names shall be uppercase #18

Closed
rgeronimi opened this issue Jul 15, 2022 · 2 comments
Closed

Enumerant names shall be uppercase #18

rgeronimi opened this issue Jul 15, 2022 · 2 comments

Comments

@rgeronimi
Copy link

rgeronimi commented Jul 15, 2022

This python doc indicates that enumerant names are lowercase:

some special currencies like ```XXX``. Enumerants names are lowercase

This creates 2 issues:

  • A syntactic one - in Python syntactic conventions are that enum members shall be uppercase
  • A computational one - if one wants to check if a currency code exists in the enum without triggering a not-found exception, the proper way is to use Currency.__members__.get(code) and check its return value for None. However the current convention requires first to convert the code to lowercase just to be able to lookup the code

Changing the convention to uppercase automatically eliminates these 2 issues, plus simplifies the code (call to lower() useless now).

@dahlia
Copy link
Owner

dahlia commented Sep 26, 2023

That's a good point, but it wouldn't be that easy to change the casing due to backwards compatibility. I'm going to add a new function to address the second issue.

@olliemath
Copy link

olliemath commented Jun 3, 2024

if one wants to check if a currency code exists in the enum without triggering a not-found exception, the proper way is to use Currency.__members__.get(code) and check its return value for None.

Just passing by, but note this isn't the proper way to check if an enum value (rather than key) is present, instead use

code in Currency._value2member_map_

for example

>>> from iso4217 import Currency
>>> "USD" in Currency._value2member_map_
True
>>> "XYZ" in Currency._value2member_map_
False

or just wrap Currency(code) in a try/except clause.

@dahlia dahlia closed this as completed in 8cb9c58 Jul 24, 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

No branches or pull requests

3 participants