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
{{ message }}
Repository navigation
LOAD_GLOBAL instruction with wrong source position #91409
You should have pasted in the actual position tuples you saw that show the presumed bug.
With 3.11.0a7, released 10 days ago, just before your report, the positions are identical (on Win 10).
>>> import dis
>>> dix=dis
>>> def f():
... dis.b()
... dix.b()
...
>>> for i in dis.Bytecode(f):
... if i.opname == "LOAD_GLOBAL":
... print(i.starts_lines, i.positions)
...
2 Positions(lineno=2, end_lineno=2, col_offset=4, end_col_offset=7)
3 Positions(lineno=2, end_lineno=2, col_offset=4, end_col_offset=7)
I don't know why the Positions.lineno does not match starts_lines, but your report is about columns. Here they match.
I am presuming that you used an earlier alpha and that the OS does not matter and that this was recently discovered and fixed.
Reopen if I missed something
@terryjreedy The problem seems is be back in 3.11.0b4 (on ubuntu)
importdisdix=5deff():
dis.b() # wrong source rangedix.b() # correct source ranged= [bcforbcindis.Bytecode(f) ifbc.opname=="LOAD_GLOBAL"]
print(d)
assertlen(d) ==2# LOAD_GLOBAL has a wrong end column if the global value is an imported moduleassertd[0].positions[2:] ==d[1].positions[2:] == (4, 7)
You changed from 'global name is an imported module name' to 'global object is an imported module. I revised by example to cover both and ran with freshly updated and compiled 'main' and '3.11' and installed 3.11.0b4'.
import dis
dix = dis
dum = 5
def f(): dis, dix, dum
for i in dis.Bytecode(f):
if i.opname == "LOAD_GLOBAL":
print(i.positions)
For all 3 names, end - start == 3. Same with each on separate line.
Please run a pasted copy of the code above on your machine. If output is different, paste a copy.
If same but minimal editing gives anomaly, paste code and output.
I got the same results like you and there are no problems if we only lookup the global variable.
Sorry for my wording error. I hope this Example will make it clear what I mean.
The source range extends to the name of the called function if we call an function on a imported module.
you can see that the method name gets included in the range. This should be not the case in my opinion. Or are there any reasons for this Behaviour? There is also no Problem for attribute lookups like dis.a.
I also bisected the bahavior change down to 3011a097bd. Maybe this helps.
@markshannon@pablogsal LOAD_GLOBAL of a name bound by import has an erroneous end_col_offset if followed by LOAD_METHOD and calls. OP bisected to #31933, 3011a097bd. (15... Thanks for doing that.)
Tests in additional to those already posted above:
import dis, abc
import ast as art
dix = dis
ast = art
def f():
dix.a() # Is first name affected if not bound name? (No.)
dis.a() # Is bound-file name affected if not first? (Yes.)
abc.a() # Are names other than 'dis' affected? (Yes.)
art.a() # Is bound name not file name affected? (Yes.)
ast.a() # Is file name not bound name affected? (No.)
for i in dis.Bytecode(f):
if i.opname == "LOAD_GLOBAL":
print(f'{i.opname:12s}', i.positions)
Thank you Brandt for the nice fix and tests. @15r10nk Thank you for persisting through the fog so we fixed a real bug which would surely have bitten someone if released.
Activity
15r10nk commentedon Apr 7, 2022
The LOAD_GLOBAL instruction has a different/wrong source position if it refers the name of an imported module.
terryjreedy commentedon Apr 15, 2022
You should have pasted in the actual position tuples you saw that show the presumed bug.
With 3.11.0a7, released 10 days ago, just before your report, the positions are identical (on Win 10).
I don't know why the Positions.lineno does not match starts_lines, but your report is about columns. Here they match.
I am presuming that you used an earlier alpha and that the OS does not matter and that this was recently discovered and fixed.
Reopen if I missed something
15r10nk commentedon Jul 16, 2022
@terryjreedy The problem seems is be back in 3.11.0b4 (on ubuntu)
output:
can we open this issue again?
terryjreedy commentedon Jul 16, 2022
You changed from 'global name is an imported module name' to 'global object is an imported module. I revised by example to cover both and ran with freshly updated and compiled 'main' and '3.11' and installed 3.11.0b4'.
Output on Win 10:
For all 3 names, end - start == 3. Same with each on separate line.
Please run a pasted copy of the code above on your machine. If output is different, paste a copy.
If same but minimal editing gives anomaly, paste code and output.
15r10nk commentedon Jul 17, 2022
I got the same results like you and there are no problems if we only lookup the global variable.
Sorry for my wording error. I hope this Example will make it clear what I mean.
The source range extends to the name of the called function if we call an function on a imported module.
output:
you can see that the method name gets included in the range. This should be not the case in my opinion. Or are there any reasons for this Behaviour? There is also no Problem for attribute lookups like
dis.a.I also bisected the bahavior change down to 3011a097bd. Maybe this helps.
terryjreedy commentedon Jul 17, 2022
@markshannon @pablogsal LOAD_GLOBAL of a name bound by import has an erroneous end_col_offset if followed by LOAD_METHOD and calls. OP bisected to #31933, 3011a097bd. (15... Thanks for doing that.)
Tests in additional to those already posted above:
outputs
GH-91409: Don't overwrite valid locations with NOP locations (GH-95067)
[3.11] pythonGH-91409: Don't overwrite valid locations with NOP locat…
[3.11] GH-91409: Don't overwrite valid locations with NOP locations (G…
terryjreedy commentedon Jul 20, 2022
Thank you Brandt for the nice fix and tests.
@15r10nk Thank you for persisting through the fog so we fixed a real bug which would surely have bitten someone if released.