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: logging: make setLevel() return handler itself for chained configuration
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: georg.brandl, techtonik, vinay.sajip
Priority: normal Keywords:

Created on 2012-05-09 07:15 by techtonik, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg160252 - (view) Author: anatoly techtonik (techtonik) Date: 2012-05-09 07:15
It would be convenient if instead of:

    hdlr = logging.StreamHandler()
    hglr.setLevel(logging.DEBUG)
    root.addHandler(hdlr)

it would be possible to write:

    root.addHandler(logging.StreamHandler().setLevel(logging.DEBUG))
msg160253 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-05-09 07:42
-1. Attribute setters or mutating methods returning self is not a common pattern in Python. See list.sort().
msg160254 - (view) Author: anatoly techtonik (techtonik) Date: 2012-05-09 07:51
List is a standard type and it have None returned for a reson. Logging is a library with its own semantic and high level object. Here you don't need to return None to explicitly say that the object was modified in place.
msg160255 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-05-09 07:53
Well, can you find any other setter method of a "high level object" in the stdlib that returns self?
msg160256 - (view) Author: anatoly techtonik (techtonik) Date: 2012-05-09 07:58
Well, I can remember any other widely used high level objects from stdlib either. HTTP servers perhaps, but they are in a poor state.
msg160257 - (view) Author: anatoly techtonik (techtonik) Date: 2012-05-09 07:58
s/can/can't/
msg160258 - (view) Author: anatoly techtonik (techtonik) Date: 2012-05-09 08:02
Well, there is argparse, but it doesn't support method chaining. Whatever, it is just a proposal. If consistency inside stdlib covers calling conventions for bundled user-level libs - I am fine with that.
msg160295 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2012-05-09 14:18
I agree with Georg. Besides, as far as possible, the API should be consistent across versions of Python, unless something is needed to take advantage of added features.

With your proposal, users could write library code which then would not work in older Python versions - and that's not something we want to encourage.
History
Date User Action Args
2022-04-11 14:57:30adminsetgithub: 58965
2012-05-09 14:18:44vinay.sajipsetstatus: open -> closed

nosy: + vinay.sajip
messages: + msg160295

assignee: vinay.sajip
resolution: wont fix
2012-05-09 08:02:33techtoniksetmessages: + msg160258
2012-05-09 07:58:48techtoniksetmessages: + msg160257
2012-05-09 07:58:14techtoniksetmessages: + msg160256
2012-05-09 07:53:51georg.brandlsetmessages: + msg160255
2012-05-09 07:51:34techtoniksetmessages: + msg160254
2012-05-09 07:42:04georg.brandlsetnosy: + georg.brandl
messages: + msg160253
2012-05-09 07:15:19techtonikcreate