This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unable to inherit from logging.Formatter
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BNMetrics, vinay.sajip, yan12125
Priority: normal Keywords:

Created on 2018-12-15 12:07 by yan12125, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg331900 - (view) Author: (yan12125) * Date: 2018-12-15 12:07
The following script runs fine on Python 3.7.1 but not on master (f5107dfd42).

import logging

class Foo(logging.Formatter):
    def __init__(self):
        super().__init__(self)

Foo()

The output is:

Traceback (most recent call last):
  File "t.py", line 9, in <module>
    Foo()
  File "t.py", line 6, in __init__
    super().__init__(self)
  File "/usr/lib/python3.8/logging/__init__.py", line 589, in __init__
    self._style.validate()
  File "/usr/lib/python3.8/logging/__init__.py", line 441, in validate
    if not self.validation_pattern.search(self._fmt):
TypeError: expected string or bytes-like object

Most likely there's something wrong in the newly-added validation step (issue34844).

/cc the primary reviewer of the aforementioned patch.
msg331929 - (view) Author: (yan12125) * Date: 2018-12-16 16:07
Hi Vinay Sajip, thanks for notifying the patch author. Just a question: is there a reason to remove 3.8 from affected versions? My sample program is indeed broken on Python 3.8.
msg332057 - (view) Author: Luna Chen (BNMetrics) * Date: 2018-12-18 12:29
Hi Chih-Hsuan Yen,
I will check this out and let you know the outcome.

Thanks! :)
msg332058 - (view) Author: Luna Chen (BNMetrics) * Date: 2018-12-18 12:59
Hi Chih-Hsuan Yen,

I have noticed in your `__init__` method, you have `super().__init__(self)`, I'm just wondering if the `self` argument is intentional, as the `Foo` object is to become the format itself?

Because inheritance seems to work fine for me with `super().__init__()`, as super() is used for the parent class object, so I don't need to pass in the `self` for the object itself. the `self` in `super().__init__(self)` becomes the value of `fmt` argument..
msg332111 - (view) Author: (yan12125) * Date: 2018-12-19 06:22
Oh so that's a simple Python question. Yep it works if `self` is removed. Thank you very much for the comment and sorry for bothering. I'll fix the code I'm using.
History
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79690
2018-12-19 06:22:22yan12125setstatus: open -> closed
resolution: not a bug
messages: + msg332111

stage: resolved
2018-12-18 12:59:23BNMetricssetmessages: + msg332058
2018-12-18 12:29:45BNMetricssetmessages: + msg332057
2018-12-16 16:07:37yan12125setmessages: + msg331929
2018-12-16 10:57:29vinay.sajipsetnosy: + BNMetrics

versions: + Python 3.6, - Python 3.8
2018-12-15 12:07:48yan12125create