PreferencesHelper with Enum trait containing Python keywords or builtins leads to errors
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with PreferencesHelper._get_value and the preference rewrite path described in the issue, reproducing the Enum trait case with the logging level "Warning". Trace how the value is evaluated and serialized; done means a keyword or builtin-named enum value remains a valid string after loading, rewriting, and reloading preferences.
Written by the indexing model from the issue text.
Description
I stumbled upon this when defining a preferences helper for a logging configuration.
When defining an Enum trait whose values contain strings that map to Python keywords or builtins (like the logging level "Warning"):

Upon initialization of the preferences, the _get_value method of the PreferencesHelper class, will call an eval on "Warning", which results in a type instance of Warning. The following Enum trait validator then fails since the Warning type in not contained in the enum.

When specifying the default preferences like this:
[application_logger]
default_level = "Warning"
works upon loading the first app startup.
But after closing the application, the user preferences are re-written, resulting in "Warning" being dumped without ticks.
A potential solution might be executing the "eval" and then dismissing results that are builtins?
Using apptools 5.1.0, traits 6.3.1, Win10
- Dominant language
- Python
- Stars
- 38
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from enthought/apptools
-
type: bug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
All issues in enthought/apptools
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100