[issue46422] Why do we need `dis.Positions`?

2022-01-24 Thread Nikita Sobolev


Change by Nikita Sobolev :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue46422] Why do we need `dis.Positions`?

2022-01-24 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:


New changeset 58f3d980989c7346ad792d464c1d749dcec6af63 by Nikita Sobolev in 
branch 'main':
bpo-46422: use `dis.Positions` in `dis.Instruction` (GH-30716)
https://github.com/python/cpython/commit/58f3d980989c7346ad792d464c1d749dcec6af63


--

___
Python tracker 

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



[issue46422] Why do we need `dis.Positions`?

2022-01-19 Thread Nikita Sobolev


Change by Nikita Sobolev :


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

___
Python tracker 

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



[issue46422] Why do we need `dis.Positions`?

2022-01-19 Thread Nikita Sobolev


Nikita Sobolev  added the comment:

Ok then, I will send my option `2` proposal to fix this later today.

--

___
Python tracker 

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



[issue46422] Why do we need `dis.Positions`?

2022-01-19 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:

The initial aim of the dis.Positions was to provide an interface like AST 
nodes. So you could do

for instr in dis.Bytecode(source):
print("located in: ", instr.positions.lineno)

instead of

for instr in dis.Bytecode(source):
if instr.positions:
lineno = instr.positions[0]
else:
lineno = None
print("located in: ", lineno)

I think this is a bug that we are not currently using it, I'd say we should use 
it properly and go with option 2.

--

___
Python tracker 

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



[issue46422] Why do we need `dis.Positions`?

2022-01-18 Thread Nikita Sobolev

New submission from Nikita Sobolev :

While working on https://github.com/python/cpython/pull/30058 I've noticed that 
`Positions` namedtuple is kinda strange, source: 
https://github.com/python/cpython/blame/8c2fd09f365e082cfceb29afdf38953cdd670946/Lib/dis.py#L204-L213

Why?
1. It is not used. `grep` shows that:

```
ยป ag Positions .  
Misc/HISTORY
21894:  treated as being relative to the end of the input string. Positions

Objects/codeobject.c
1021:static PyTypeObject PositionsIterator = {
1067:positionsiterator* pi = 
(positionsiterator*)PyType_GenericAlloc(, 0);

Mac/PythonLauncher/English.lproj/MainMenu.nib/info.nib
7:  IBEditorPositions

Lib/dis.py
204:Positions = collections.namedtuple(
205:'Positions',
239:_Instruction.positions.__doc__ = "dis.Positions object holding the span of 
source code covered by this instruction"
259: positions - Optional dis.Positions object holding the span of 
source code

Lib/test/test_compile.py
1013:class TestSourcePositions(unittest.TestCase):

Doc/library/re.rst
1579:Finding all Adverbs and their Positions
```

2. Commenting it out does not make `test_dis` to fail (again, because it does 
not seem to be used)
3. It is documented (in docstrings only, not in `dis.rst`) that 
`Instruction.positions` is `dis.Positions`, but this is not true. Because 
`Instruction` is created as:

```python
co_positions = co_positions or iter(())

try:
  positions = next(co_positions)
except StopIteration:
  positions = None

Instruction(positions=positions)
```

So, it is at best is `tuple | None`. Never `Positions`.

What to do with it?
1. Should it be removed as unused, undocumented, and unreleased?
2. Should it be used as documented? Here: 
https://github.com/python/cpython/blame/8c2fd09f365e082cfceb29afdf38953cdd670946/Lib/dis.py#L453-L455
3. Any other ideas?

In my opinion, it is not required, because we already have 
`codeobject.co_positions` which is pretty much the same thing: 
https://docs.python.org/3.11/reference/datamodel.html?highlight=co_positions#codeobject.co_positions

I would like to work on it after a final decision is made :)

--
components: Library (Lib)
messages: 410855
nosy: BTaskaya, pablogsal, sobolevn
priority: normal
severity: normal
status: open
title: Why do we need `dis.Positions`?
type: behavior
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