Skip to content

Commit 1db8e88

Browse files
committed
Strip trailing _ from config members, to bypass Python reserved words
Example of adding an `async` boolean option that can be read through `config['async']` or `config.async_`: class ExampleConfig(Config): async_ = Type(bool, default=False)
1 parent fce89f7 commit 1db8e88

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mkdocs/config/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def post_validation(self, config: Config, key_name: str) -> None:
6969
"""
7070

7171
def __set_name__(self, owner, name):
72+
if name.endswith('_') and not name.startswith('_'):
73+
name = name[:-1]
7274
self._name = name
7375

7476
@overload
@@ -123,7 +125,7 @@ def __init_subclass__(cls):
123125
schema = dict(getattr(cls, '_schema', ()))
124126
for attr_name, attr in cls.__dict__.items():
125127
if isinstance(attr, BaseConfigOption):
126-
schema[attr_name] = attr
128+
schema[getattr(attr, '_name', attr_name)] = attr
127129
cls._schema = tuple(schema.items())
128130

129131
for attr_name, attr in cls._schema:

0 commit comments

Comments
 (0)