classification
Title: imp.find_module() return value documentation discrepancy
Type: Stage: patch review
Components: Documentation Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: StefanBauerTT, Windson Yang, brett.cannon, docs@python
Priority: normal Keywords: patch

Created on 2018-11-27 07:27 by StefanBauerTT, last changed 2019-01-05 05:28 by xtreak.

Pull Requests
URL Status Linked Edit
PR 11040 open Windson Yang, 2018-12-09 01:53
Messages (4)
msg330495 - (view) Author: Stefan Bauer (TraceTronic) (StefanBauerTT) Date: 2018-11-27 07:27
I’d like to report a discrepancy between the documentation and implementation of the method imp.find_module().

The documentation <https://docs.python.org/3.7/library/imp.html#imp.find_module> currently says “If the module does not live in a file, the returned file is None, pathname is the __empty_string__, […]”

The implementation <https://github.com/python/cpython/blob/master/Lib/imp.py#L272>, on the other hand, returns __None__ for built-in and frozen modules.

Yours,
Stefan
msg330739 - (view) Author: Windson Yang (Windson Yang) * Date: 2018-11-30 00:40
If I understand correctly, this may be better.

Try to find the module name. If path is omitted or None, the list of directory names given by sys.path is searched. If path is built-in or frozen modules, return None instead.

BTW, the dosstring should also be updated, I will not continue search the path if the path in build-in or frozen. and this module is deprecated since version 3.4
msg331489 - (view) Author: Stefan Bauer (TraceTronic) (StefanBauerTT) Date: 2018-12-10 10:45
Hi, thank you for your proposal. However, your version still contains the discepancy. Maybe I formulated the problem not clear, so let's try again:

The documentation should state that "pathname" will be None (not the empty string) for built-in and frozen modules in order to be in line with the implementation.

Thank you very much for your efforts.
Kind regards, Stefan
msg333035 - (view) Author: Windson Yang (Windson Yang) * Date: 2019-01-05 02:54
> The documentation should state that "pathname" will be None (not the empty string) for built-in and frozen modules in order to be in line with the implementation.

Both the "file" and "pathname" will be None for built-in and frozen modules, right? In the PR @ericsnowcurrently suggested add:

>  If the module is built-in or frozen then *file* and *pathname* are both ``None`` and the *description* tuple contains empty...

I think it also works.
History
Date User Action Args
2019-01-05 05:28:12xtreaksetnosy: + brett.cannon

versions: - Python 3.4, Python 3.5, Python 3.6
2019-01-05 02:54:51Windson Yangsetmessages: + msg333035
2018-12-10 10:45:28StefanBauerTTsetmessages: + msg331489
2018-12-09 01:53:16Windson Yangsetkeywords: + patch
stage: patch review
pull_requests: + pull_request10277
2018-11-30 00:40:10Windson Yangsetnosy: + Windson Yang

messages: + msg330739
versions: + Python 3.4, Python 3.5, Python 3.6
2018-11-27 07:27:04StefanBauerTTcreate