Skip to content

Commit 4573146

Browse files
author
y-p
committed
ENH: option names must valid, non-keyword python identifiers
1 parent 8177ee5 commit 4573146

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/core/config.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def register_option(key, defval, doc='', validator=None, cb=None):
349349
ValueError if `validator` is specified and `defval` is not a valid value.
350350
351351
"""
352-
352+
import tokenize, keyword
353353
key = key.lower()
354354

355355
if key in _registered_options:
@@ -363,6 +363,13 @@ def register_option(key, defval, doc='', validator=None, cb=None):
363363

364364
# walk the nested dict, creating dicts as needed along the path
365365
path = key.split('.')
366+
367+
for k in path:
368+
if not bool(re.match('^'+tokenize.Name+'$', k)):
369+
raise ValueError("%s is not a valid identifier" % k)
370+
if keyword.iskeyword(key):
371+
raise ValueError("%s is a python keyword" % k)
372+
366373
cursor = _global_config
367374
for i, p in enumerate(path[:-1]):
368375
if not isinstance(cursor, dict):

0 commit comments

Comments
 (0)