Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception text is being sourced from the wrong file #80440

Open
rhubarbdogx mannequin opened this issue Mar 11, 2019 · 4 comments
Open

exception text is being sourced from the wrong file #80440

rhubarbdogx mannequin opened this issue Mar 11, 2019 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@rhubarbdogx
Copy link
Mannequin

rhubarbdogx mannequin commented Mar 11, 2019

BPO 36259
Nosy @stevendaprano, @tirkarthi, @jessefarnham

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 = None
closed_at = None
created_at = <Date 2019-03-11.01:51:16.936>
labels = ['3.8', 'type-bug', '3.7']
title = 'exception text is being sourced from the wrong file'
updated_at = <Date 2019-04-07.19:04:59.497>
user = 'https://bugs.python.org/rhubarbdogx'

bugs.python.org fields:

activity = <Date 2019-04-07.19:04:59.497>
actor = 'jesse.farnham'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2019-03-11.01:51:16.936>
creator = 'rhubarbdog x'
dependencies = []
files = []
hgrepos = []
issue_num = 36259
keywords = []
message_count = 4.0
messages = ['337642', '337647', '339581', '339582']
nosy_count = 4.0
nosy_names = ['steven.daprano', 'xtreak', 'jesse.farnham', 'rhubarbdog x']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue36259'
versions = ['Python 2.7', 'Python 3.7', 'Python 3.8']

@rhubarbdogx
Copy link
Mannequin Author

rhubarbdogx mannequin commented Mar 11, 2019

Hi
i have a directory containing a directory bug and the python program bad.py. The code for bad.py is

import os

os.chdir('bug')
print(7/0)

directory bug contains a file bad.py this file contents are

test 1
test 2
test 3
test 4
test 5
test 6

when i run the python script i get the error text

Traceback (most recent call last):
  File "bad.py", line 4, in <module>
    test 4
ZeroDivisionError: division by zero

@rhubarbdogx rhubarbdogx mannequin added the type-bug An unexpected behavior, bug, or error label Mar 11, 2019
@tirkarthi
Copy link
Member

I noticed a similar report in the past where using chdir causes pdb to use the file path relative to the directory where it chdir to . I am not sure if both are same but the issue I am talking about is bpo-33139

@ronaldoussoren ronaldoussoren added 3.7 (EOL) end of life 3.8 only security fixes labels Mar 11, 2019
@jessefarnham
Copy link
Mannequin

jessefarnham mannequin commented Apr 7, 2019

I did some digging into this, and the problem seems to be that _Py_FindSourceFile() in traceback.c searches through every directory in sys.path (of which the first entry is the working directory) to find a file with the passed filename. So if there's a file in the working directory with name matching the filename passed in from the traceback object, _Py_FindSourceFile will find that one, resulting in the wrong listing being printed.

Does the traceback object contain any other information that would avoid the need to search sys.path to find the right file? If it can know the file name, maybe there's a way to find the file path as well?

Apologies if this is not useful -- this is my first attempt to contribute to Python.

@jessefarnham
Copy link
Mannequin

jessefarnham mannequin commented Apr 7, 2019

Upon further digging, the filename to search for ultimately comes from the PyCodeObject where the error occurred. So a possible solution could be to populate the PyCodeObject with the absolute path to the file when it’s first created in compilation. Then no searching is needed and the problem doesn’t happen. This seems like a potentially very invasive change, though.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added interpreter-core (Objects, Python, Grammar, and Parser dirs) and removed 3.8 only security fixes 3.7 (EOL) end of life labels Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants