You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2022-01-24.11:27:21.615>created_at=<Date2022-01-18.12:30:08.000>labels= ['type-bug', 'library', '3.11']
title='Why do we need `dis.Positions`?'updated_at=<Date2022-01-24.11:27:21.615>user='https://github.com/sobolevn'
» 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(&PositionsIterator, 0);
Mac/PythonLauncher/English.lproj/MainMenu.nib/info.nib
7: <key>IBEditorPositions</key>
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
Commenting it out does not make test_dis to fail (again, because it does not seem to be used)
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:
Activity
sobolevn commentedon Jan 18, 2022
While working on #30058 I've noticed that
Positionsnamedtuple is kinda strange, source:https://github.com/python/cpython/blame/8c2fd09f365e082cfceb29afdf38953cdd670946/Lib/dis.py#L204-L213
Why?
grepshows that:test_disto fail (again, because it does not seem to be used)dis.rst) thatInstruction.positionsisdis.Positions, but this is not true. BecauseInstructionis created as:So, it is at best is
tuple | None. NeverPositions.What to do with it?
In my opinion, it is not required, because we already have
codeobject.co_positionswhich is pretty much the same thing: https://docs.python.org/3.11/reference/datamodel.html?highlight=co_positions#codeobject.co_positionsI would like to work on it after a final decision is made :)
isidentical commentedon Jan 19, 2022
The initial aim of the dis.Positions was to provide an interface like AST nodes. So you could do
instead of
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.
sobolevn commentedon Jan 19, 2022
Ok then, I will send my option
2proposal to fix this later today.isidentical commentedon Jan 24, 2022
New changeset 58f3d98 by Nikita Sobolev in branch 'main':
bpo-46422: use
dis.Positionsindis.Instruction(GH-30716)58f3d98