8000 Merge branch 'main' into issue-111906 · python/cpython@4717fb0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4717fb0

Browse files
authored
Merge branch 'main' into issue-111906
2 parents cd4882a + a5f29c9 commit 4717fb0

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

Doc/howto/enum.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,9 @@ The complete signature is::
607607
start=1,
608608
)
609609

610-
:value: What the new enum class will record as its name.
610+
* *value*: What the new enum class will record as its name.
611611

612-
:names: The enum members. This can be a whitespace- or comma-separated string
612+
* *names*: The enum members. This can be a whitespace- or comma-separated string
613613
(values will start at 1 unless otherwise specified)::
614614

615615
'RED GREEN BLUE' | 'RED,GREEN,BLUE' | 'RED, GREEN, BLUE'
@@ -626,13 +626,13 @@ The complete signature is::
626626

627627
{'CHARTREUSE': 7, 'SEA_GREEN': 11, 'ROSEMARY': 42}
628628

629-
:module: name of module where new enum class can be found.
629+
* *module*: name of module where new enum class can be found.
630630

631-
:qualname: where in module new enum class can be found.
631+
* *qualname*: where in module new enum class can be found.
632632

633-
:type: type to mix in to new enum class.
633+
* *type*: type to mix in to new enum class.
634634

635-
:start: number to start counting at if only names are passed in.
635+
* *start*: number to start counting at if only names are passed in.
636636

637637
.. versionchanged:: 3.5
638638
The *start* parameter was added.

Lib/logging/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ def configure_custom(self, config):
482482
c = config.pop('()')
483483
if not callable(c):
484484
c = self.resolve(c)
485-
props = config.pop('.', None)
486485
# Check for valid identifiers
487-
kwargs = {k: config[k] for k in config if valid_ident(k)}
486+
kwargs = {k: config[k] for k in config if (k != '.' and valid_ident(k))}
488487
result = c(**kwargs)
488+
props = config.pop('.', None)
489489
if props:
490490
for name, value in props.items():
491491
setattr(result, name, value)
@@ -835,8 +835,7 @@ def configure_handler(self, config):
835835
factory = functools.partial(self._configure_queue_handler, klass)
836836
else:
837837
factory = klass
838-
props = config.pop('.', None)
839-
kwargs = {k: config[k] for k in config if valid_ident(k)}
838+
kwargs = {k: config[k] for k in config if (k != '.' and valid_ident(k))}
840839
try:
841840
result = factory(**kwargs)
842841
except TypeError as te:
@@ -854,6 +853,7 @@ def configure_handler(self, config):
854853
result.setLevel(logging._checkLevel(level))
855854
if filters:
856855
self.add_filters(result, filters)
856+
props = config.pop('.', None)
857857
if props:
858858
for name, value in props.items():
859859
setattr(result, name, value)

Lib/test/test_logging.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2998,6 +2998,39 @@ class ConfigDictTest(BaseTest):
29982998
},
29992999
}
30003000

3001+
class CustomFormatter(logging.Formatter):
3002+
custom_property = "."
3003+
3004+
def format(self, record):
3005+
return super().format(record)
3006+
3007+
config17 = {
3008+
'version': 1,
3009+
'formatters': {
3010+
"custom": {
3011+
"()": CustomFormatter,
3012+
"style": "{",
3013+
"datefmt": "%Y-%m-%d %H:%M:%S",
3014+
"format": "{message}", # <-- to force an exception when configuring
3015+
".": {
3016+
"custom_property": "value"
3017+
}
3018+
}
3019+
},
3020+
'handlers' : {
3021+
'hand1' : {
3022+
'class' : 'logging.StreamHandler',
3023+
'formatter' : 'custom',
3024+
'level' : 'NOTSET',
3025+
'stream' : 'ext://sys.stdout',
3026+
},
3027+
},
3028+
'root' : {
3029+
'level' : 'WARNING',
3030+
'handlers' : ['hand1'],
3031+
},
3032+
}
3033+
30013034
bad_format = {
30023035
"version": 1,
30033036
"formatters": {
@@ -3479,7 +3512,10 @@ def test_config16_ok(self):
34793512
{'msg': 'Hello'}))
34803513
self.assertEqual(result, 'Hello ++ defaultvalue')
34813514

3482-
3515+
def test_config17_ok(self):
3516+
self.apply_config(self.config17)
3517+
h = logging._handlers['hand1']
3518+
self.assertEqual(h.formatter.custom_property, 'value')
34833519

34843520
def setup_via_listener(self, text, verify=None):
34853521
text = text.encode("utf-8")

0 commit comments

Comments
 (0)
0