[New-bugs-announce] [issue46422] Why do we need `dis.Positions`?

Nikita Sobolev report at bugs.python.org
Tue Jan 18 07:30:08 EST 2022

New submission from Nikita Sobolev <mail at sobolevn.me>:

While working on https://github.com/python/cpython/pull/30058 I've noticed that `Positions` namedtuple is kinda strange, source: 

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

» ag Positions .  
21894:  treated as being relative to the end of the input string. Positions

1021:static PyTypeObject PositionsIterator = {
1067:    positionsiterator* pi = (positionsiterator*)PyType_GenericAlloc(&PositionsIterator, 0);

7:      <key>IBEditorPositions</key>

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

1013:class TestSourcePositions(unittest.TestCase):

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:

co_positions = co_positions or iter(())

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


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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list