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: f-string debugging f"{x=[}" adds [filename:lineno] as prefix
Type: enhancement Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: aldwinaldwin, xtreak
Priority: normal Keywords: patch

Created on 2019-06-04 08:54 by aldwinaldwin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13799 closed aldwinaldwin, 2019-06-04 08:59
Messages (4)
msg344533 - (view) Author: Aldwin Pollefeyt (aldwinaldwin) * Date: 2019-06-04 08:54
From this idea [0] by Karthikeyan Singaravelan and added to his code in hack [1].

name = "karthikeyan"
print(f"{name =[}")
print(f"{name=[}")
print(f"{age = [}")
print(f"{age= [}")

[prog.py:2] name ='karthikeyan'
[prog.py:3] name='karthikeyan'
[prog.py:4] name = 'karthikeyan'
[prog.py:5] name= 'karthikeyan'


[0] https://tirkarthi.github.io/programming/2019/05/08/f-string-debugging.html

[1] https://github.com/tirkarthi/cpython/commit/d0fcbe67f6bb8ad60744b0a4973c4dc69fda65a9
msg344534 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-06-04 09:22
I created a post about it for discussion [0]. There is no consensus on the format and to modify the existing debugging notation. There were also suggestions to include a builtin function (dbg) like breakpoint() that does this. I guess implementation can be discussed once the idea is accepted to avoid work being wasted. It certainly can go only in 3.9 if accepted given 3.8 beta release.

[0] https://discuss.python.org/t/filename-and-line-number-in-f-string-debugging-output/1650/8
msg344535 - (view) Author: Aldwin Pollefeyt (aldwinaldwin) * Date: 2019-06-04 09:25
Ok, didn't know about discuss.python.org. Searching on all PR and bpo's there was no reference to your hack. Will investigate this discuss.python.org. Ai ai ai, more info to read.
msg344536 - (view) Author: Aldwin Pollefeyt (aldwinaldwin) * Date: 2019-06-04 09:40
Can use:

import logging

l = logging.Logger("")
h = logging.StreamHandler()
f = logging.Formatter(fmt="[{filename}:{lineno}] {msg}", style="{")
h.setFormatter(f)
l.addHandler(h)
l.info("Hello")

Output:

>py .\t.py
[t.py:8] Hello
History
Date User Action Args
2022-04-11 14:59:16adminsetgithub: 81328
2019-06-04 09:40:36aldwinaldwinsetstatus: open -> closed
resolution: not a bug
messages: + msg344536

stage: patch review -> resolved
2019-06-04 09:25:41aldwinaldwinsetmessages: + msg344535
2019-06-04 09:22:27xtreaksetmessages: + msg344534
2019-06-04 08:59:04aldwinaldwinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request13684
2019-06-04 08:54:23aldwinaldwincreate