[issue46652] Use code.co_qualname to provide richer information

2022-02-06 Thread Gabriele N Tornetta


Gabriele N Tornetta  added the comment:

code.co_qualname was introduced in 2021 with bpo-44530 and shuold give the same 
guarantees as code.co_name. The __qualname__ attribute is derived from 
code.co_qualname, so perhaps Cython can benefit from accessing code.co_qualname 
directly instead?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46652] Use code.co_qualname to provide richer information

2022-02-05 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Similar changes at bpo-40679 accidentally broke Cython when it was assumed that 
co_qualname was non-null, which was then fixed by defaulting to co_name in that 
case. I don't know if Cython still produces cases like that, but we should make 
sure not to needlessly break such cases if it does.

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46652] Use code.co_qualname to provide richer information

2022-02-05 Thread Andre Roberge


Change by Andre Roberge :


--
nosy: +aroberge

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46652] Use code.co_qualname to provide richer information

2022-02-05 Thread Gabriele N Tornetta


Change by Gabriele N Tornetta :


--
keywords: +patch
pull_requests: +29327
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31150

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46652] Use code.co_qualname to provide richer information

2022-02-05 Thread Gabriele N Tornetta

New submission from Gabriele N Tornetta :

https://bugs.python.org/issue44530 introduced the co_qualname field to code 
objects. This could be used to, e.g. enrich the information provided by 
tracebacks. Consider this simple example

~~~ python
import traceback


class Bogus:
def __init__(self):
traceback.print_stack()
raise RuntimeError("Oh no!")


class Foo:
def __init__(self):
Bogus()


Foo()
~~~

The current output is

~~~
❯ python3.10 test_tb_format.py  
 
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 15, in 
Foo()
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 12, in __init__
Bogus()
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 6, in __init__
traceback.print_stack()
Traceback (most recent call last):
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 15, in 
Foo()
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 12, in __init__
Bogus()
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 7, in __init__
raise RuntimeError("Oh no!")
RuntimeError: Oh no!
~~~

The proposed change is to use the co_qualname field instead of co_name to 
provide more immediate information about the distinct functions __init__, viz.

~~~
❯ ./python test_tb_format.py   
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 15, in 
Foo()
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 12, in 
Foo.__init__
Bogus()
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 6, in 
Bogus.__init__
traceback.print_stack()
Traceback (most recent call last):
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 15, in 
Foo()
^
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 12, in 
Foo.__init__
Bogus()
^^^
  File "/home/gabriele/Projects/cpython/test_tb_format.py", line 7, in 
Bogus.__init__
raise RuntimeError("Oh no!")

RuntimeError: Oh no!
~~~

This makes it clear that two distinct __init__ functions are involved, without 
having to look at sources.

--
components: Interpreter Core
messages: 412598
nosy: Gabriele Tornetta, pablogsal
priority: normal
severity: normal
status: open
title: Use code.co_qualname to provide richer information
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com