This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inspect.getabsfile() is not documented
Type: Stage: patch review
Components: Documentation Versions: Python 3.8, Python 3.7, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: akitada, corona10, hieu.nguyen, pitrou, remi.lapeyre, terry.reedy
Priority: normal Keywords: patch, patch, patch

Created on 2011-06-11 19:18 by giampaolo.rodola, last changed 2022-04-11 14:57 by admin.

Pull Requests
URL Status Linked Edit
PR 11786 closed corona10, 2019-02-08 03:15
PR 11786 closed corona10, 2019-02-08 03:15
PR 11786 closed corona10, 2019-02-08 03:15
Messages (8)
msg138558 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-06-17 22:58
>>> help(inspect.getabsfile) could be copied

getabsfile(object, _filename=None)
    Return an absolute path to the source or compiled file for an object.
    
    The idea is for each object to have a unique origin, so this routine
    normalizes the result as much as possible.
msg197332 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-09-08 22:21
This shouldn't be a dependency. The function is already implemented, it just needs to be documented.
msg197334 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-09-08 22:49
It technically doesn't need to be a dependency, but if __file__ goes absolute then the point of the function becomes moot and thus shouldn't get documented as it is then pointless (and honestly I don't trust any code that tries to guess at what the cwd was when a module was imported).
msg335051 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2019-02-08 01:43
@pitrou
Hi, Can I work on this issue?
msg335052 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-02-08 01:48
Hi @corona10, Antoine's message is from 2013 and inspect.getabsfile() is still not documented, I think it's safe to say he's not working on it.

You can work on the issue and open a new PR on GitHub when you think it is ready for review :)
msg335055 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-02-08 03:55
3.6 is also on security-fix-only status
msg335152 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2019-02-10 13:01
@terry.reedy
I submited the PR 11786 for this issue.
If you are okay can you take a look please?
Thanks!
msg335179 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-02-10 23:20
Given the absence of agreement among core-devs, a PR is a bit premature.  

Looking again at the existing docstring, I think it must be revised before copying and *not* copied as is.

0. The existing first sentence mislead me.  The 'source or compiled file' must be a Python source or compiled Python (.pyc) file.  An object in a compiled C file gives a TypeError.  Change 'an object' to 'a Python-coded object'.

1. The 'object' argument cannot be just any Python-coded object (class object instance).  Based on the exception message, add this second sentence: "The object must be a module, class, method, function, traceback, frame, or code object."  Otherwise, TypeError.

2. The second paragraph is garbled.  All objects in a module have a common origin, not a unique origin.  I think the idea is that the name for the origin should be a standardized full path.  I think that this paragraph adds so little that it should be deleted rather than revised.

What paused this issue was Brett's opinion that getabsfile is untrustworthy and, with __file__ absolute, 'pointless', to a degree that it should not be documented. (If that were true, it should be deprecated.)

I read the 3.7.2 source for getabsfile, getsourcefile, and getfile. The returned name is based on either module.__file__ or code.co_filename. I think the function should be kept and documented.

1. Assuming that both __file__ and co_filename are now normcased and normalized absolute paths, (and identical for functions,) then "os.path.normcase(os.path.abspath(_filename))" is a no-op returning _filename as is, and should be dropped.  There is no longer a "guess at what the cwd was when a module was imported" in getabsfile itself.

2. getfile and getsourcefile do non-trivial switching and name processing that users would not get right if getabsfile were not present.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56526
2019-02-14 23:34:13giampaolo.rodolasetkeywords: patch, patch, patch
nosy: - giampaolo.rodola
2019-02-14 20:46:37brett.cannonsetkeywords: patch, patch, patch
nosy: - brett.cannon
2019-02-10 23:20:29terry.reedysetkeywords: patch, patch, patch

messages: + msg335179
2019-02-10 13:01:55corona10setmessages: + msg335152
2019-02-08 03:55:33terry.reedysetkeywords: patch, patch, patch

messages: + msg335055
versions: - Python 3.6
2019-02-08 03:16:04corona10setkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request11778
2019-02-08 03:15:50corona10setkeywords: + patch
stage: needs patch -> needs patch
pull_requests: + pull_request11777
2019-02-08 03:15:36corona10setkeywords: + patch
stage: needs patch -> needs patch
pull_requests: + pull_request11776
2019-02-08 01:48:02remi.lapeyresetnosy: + remi.lapeyre

messages: + msg335052
versions: + Python 3.6, Python 3.7, Python 3.8, - Python 3.3, Python 3.4
2019-02-08 01:43:20corona10setnosy: + corona10
messages: + msg335051
2014-06-14 15:06:19giampaolo.rodolasetassignee: giampaolo.rodola ->
2013-09-08 22:49:34brett.cannonsetmessages: + msg197334
2013-09-08 22:21:22pitrousetnosy: + pitrou
dependencies: - Move to absolute file paths for module.__file__
messages: + msg197332
2013-09-08 22:13:53brett.cannonsetdependencies: + Move to absolute file paths for module.__file__
2013-09-08 17:05:17pitrousetnosy: + brett.cannon

versions: + Python 3.4, - Python 3.2
2013-09-08 16:10:25akitadasetnosy: + akitada
2012-10-25 22:57:16hieu.nguyensetnosy: + hieu.nguyen
2011-06-17 22:58:28terry.reedysetversions: - Python 2.6, Python 3.1
nosy: + terry.reedy

messages: + msg138558

components: + Documentation
stage: needs patch
2011-06-11 19:18:14giampaolo.rodolacreate