diff --git a/IPython/config/loader.py b/IPython/config/loader.py
index 12752d000..196ed4932 100644
--- a/IPython/config/loader.py
+++ b/IPython/config/loader.py
@@ -11,6 +11,7 @@
 import re
 import sys
 import json
+from ast import literal_eval
 
 from IPython.utils.path import filefind, get_ipython_dir
 from IPython.utils import py3compat
@@ -487,7 +488,7 @@ def _exec_config_str(self, lhs, rhs):
         """execute self.config.<lhs> = <rhs>
         
         * expands ~ with expanduser
-        * tries to assign with raw eval, otherwise assigns with just the string,
+        * tries to assign with literal_eval, otherwise assigns with just the string,
           allowing `--C.a=foobar` and `--C.a="foobar"` to be equivalent.  *Not*
           equivalent are `--C.a=4` and `--C.a='4'`.
         """
@@ -496,8 +497,8 @@ def _exec_config_str(self, lhs, rhs):
             # Try to see if regular Python syntax will work. This
             # won't handle strings as the quote marks are removed
             # by the system shell.
-            value = eval(rhs)
-        except (NameError, SyntaxError):
+            value = literal_eval(rhs)
+        except (NameError, SyntaxError, ValueError):
             # This case happens if the rhs is a string.
             value = rhs
 

commandline parser can't handle --something="all"
It seems that parsing `all` will convert it to the `all()` function and an error is shown:

```python
knitpy_aliases.update({
    'to' : 'KnitpyApp.export_format',
    [...]
})

class KnitpyApp(BaseIPythonApplication):
    # '--to' ends up here
    export_format = CaselessStrEnum(VALID_OUTPUT_FORMATS+["all"],
        default_value=DEFAULT_OUTPUT_FORMAT,
        config=True,
        help="""The export format to be used."""
    )
```

and then when I call it:
```
$ knitpy --to="all" example\hello.pymd # or `--to=all`
[...]
[KnitpyApp] CRITICAL | The 'export_format' trait of a KnitpyApp instance must be
 any of [u'pdf', u'docx', u'html', u'all'] or None, but a value of <built-in fun
ction all> <type 'builtin_function_or_method'> was specified.
```
diff --git a/IPython/config/tests/test_loader.py b/IPython/config/tests/test_loader.py
index a5fc91dd8..dc8f2573d 100644
--- a/IPython/config/tests/test_loader.py
+++ b/IPython/config/tests/test_loader.py
@@ -33,7 +33,7 @@
 c.a=10
 c.b=20
 c.Foo.Bar.value=10
-c.Foo.Bam.value=list(range(10))  # list() is just so it's the same on Python 3
+c.Foo.Bam.value=list(range(10))
 c.D.C.value='hi there'
 """
 
@@ -188,14 +188,23 @@ def test_argv(self):
 class TestKeyValueCL(TestCase):
     klass = KeyValueConfigLoader
 
+    def test_eval(self):
+        cl = self.klass(log=log)
+        config = cl.load_config('--Class.str_trait=all --Class.int_trait=5 --Class.list_trait=["hello",5]'.split())
+        self.assertEqual(config.Class.str_trait, 'all')
+        self.assertEqual(config.Class.int_trait, 5)
+        self.assertEqual(config.Class.list_trait, ["hello", 5])
+
     def test_basic(self):
         cl = self.klass(log=log)
-        argv = ['--'+s.strip('c.') for s in pyfile.split('\n')[2:-1]]
+        argv = [ '--' + s[2:] for s in pyfile.split('\n') if s.startswith('c.') ]
+        print(argv)
         config = cl.load_config(argv)
         self.assertEqual(config.a, 10)
         self.assertEqual(config.b, 20)
         self.assertEqual(config.Foo.Bar.value, 10)
-        self.assertEqual(config.Foo.Bam.value, list(range(10)))
+        # non-literal expressions are not evaluated
+        self.assertEqual(config.Foo.Bam.value, 'list(range(10))')
         self.assertEqual(config.D.C.value, 'hi there')
     
     def test_expanduser(self):

pip install -e .[test]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio
apt-get update apt-get install -y gcc
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
execnet==1.9.0
idna==3.10
importlib-metadata==4.8.3
iniconfig==1.1.1
-e git+https://github.com/ipython/ipython.git@d4e786e20631074a8713f78c7103dcab0c72b840#egg=ipython
nose==1.3.7
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
pytest-asyncio==0.16.0
pytest-cov==4.0.0
pytest-mock==3.6.1
pytest-xdist==3.0.2
requests==2.27.1
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
zipp==3.6.0

name: ipython
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - charset-normalizer==2.0.12
      - coverage==6.2
      - execnet==1.9.0
      - idna==3.10
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - nose==1.3.7
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-asyncio==0.16.0
      - pytest-cov==4.0.0
      - pytest-mock==3.6.1
      - pytest-xdist==3.0.2
      - requests==2.27.1
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - zipp==3.6.0
prefix: /opt/conda/envs/ipython

IPython/config/tests/test_loader.py::TestKeyValueCL::test_basic IPython/config/tests/test_loader.py::TestKeyValueCL::test_eval IPython/config/tests/test_loader.py::TestArgParseKVCL::test_basic
IPython/config/tests/test_loader.py::TestFileCL::test_collision IPython/config/tests/test_loader.py::TestFileCL::test_json IPython/config/tests/test_loader.py::TestFileCL::test_python IPython/config/tests/test_loader.py::TestFileCL::test_v2raise IPython/config/tests/test_loader.py::TestArgParseCL::test_add_arguments IPython/config/tests/test_loader.py::TestArgParseCL::test_argv IPython/config/tests/test_loader.py::TestArgParseCL::test_basic IPython/config/tests/test_loader.py::TestKeyValueCL::test_expanduser IPython/config/tests/test_loader.py::TestKeyValueCL::test_extra_args IPython/config/tests/test_loader.py::TestKeyValueCL::test_unicode_alias IPython/config/tests/test_loader.py::TestKeyValueCL::test_unicode_args IPython/config/tests/test_loader.py::TestArgParseKVCL::test_eval IPython/config/tests/test_loader.py::TestArgParseKVCL::test_expanduser IPython/config/tests/test_loader.py::TestArgParseKVCL::test_expanduser2 IPython/config/tests/test_loader.py::TestArgParseKVCL::test_extra_args IPython/config/tests/test_loader.py::TestArgParseKVCL::test_unicode_alias IPython/config/tests/test_loader.py::TestArgParseKVCL::test_unicode_args IPython/config/tests/test_loader.py::TestConfig::test_auto_section IPython/config/tests/test_loader.py::TestConfig::test_builtin IPython/config/tests/test_loader.py::TestConfig::test_contains IPython/config/tests/test_loader.py::TestConfig::test_deepcopy IPython/config/tests/test_loader.py::TestConfig::test_fromdict IPython/config/tests/test_loader.py::TestConfig::test_fromdictmerge IPython/config/tests/test_loader.py::TestConfig::test_fromdictmerge2 IPython/config/tests/test_loader.py::TestConfig::test_getattr_not_section IPython/config/tests/test_loader.py::TestConfig::test_getattr_private_missing IPython/config/tests/test_loader.py::TestConfig::test_getattr_section IPython/config/tests/test_loader.py::TestConfig::test_getitem_not_section IPython/config/tests/test_loader.py::TestConfig::test_getitem_section IPython/config/tests/test_loader.py::TestConfig::test_merge_copies IPython/config/tests/test_loader.py::TestConfig::test_merge_doesnt_exist IPython/config/tests/test_loader.py::TestConfig::test_merge_exists IPython/config/tests/test_loader.py::TestConfig::test_pickle_config IPython/config/tests/test_loader.py::TestConfig::test_setget
IPython/config/loader.py
IPython/config/loader.py