classification
Title: stdlib import mistaken for local by import_fixer
Type: behavior Stage: patch review
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Romuald, ced, eric.araujo, lregebro
Priority: normal Keywords: patch

Created on 2013-03-10 20:22 by lregebro, last changed 2019-10-16 21:15 by Romuald.

Pull Requests
URL Status Linked Edit
PR 16826 open Romuald, 2019-10-16 21:15
Messages (4)
msg183894 - (view) Author: Lennart Regebro (lregebro) Date: 2013-03-10 20:22
If you have a local folder (without an __init__.py, hence just a normal folder) with the same name as a non local module, the import statements of that module will assumed to be local and transformed from for example ``import datetime`` to ``from . import datetime``.
msg183925 - (view) Author: √Čric Araujo (eric.araujo) * (Python committer) Date: 2013-03-11 04:34
This is the cause for #13317
msg183936 - (view) Author: Lennart Regebro (lregebro) Date: 2013-03-11 06:08
Not really, but they are related. The fixer looks for a local module, and if it finds it it will assume the import is local. 

#13317 is caused by it not finding the module, since it's not built and hence assuming it's a global import.

This bug, contrariwise, is cause by the fixer finding a folder, and therefore assuming it is a local import when it's not.

The fix for this is to check that the folder has an __init__.py. The fix for #13317 is to build extensions before running 2to3.

Neither of them are huge problems since you can avoid both bugs but not using relative imports. :-)
msg354801 - (view) Author: Romuald Brunet (Romuald) * Date: 2019-10-16 14:36
Confirming that this issue is still present on 3.8 (and working on a fix)
History
Date User Action Args
2019-10-16 21:15:07Romualdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16376
2019-10-16 14:36:34Romualdsetmessages: + msg354801
2019-10-16 14:35:42Romualdsetnosy: + Romuald
2014-02-04 01:28:04cedsetnosy: + ced
2013-03-11 06:08:03lregebrosetmessages: + msg183936
2013-03-11 04:34:30eric.araujosetnosy: + eric.araujo
messages: + msg183925
2013-03-10 20:23:14lregebrosettype: behavior
2013-03-10 20:22:54lregebrocreate