Issue 36056: importlib does not support pathlib (original) (raw)

Created on 2019-02-20 19:02 by majuscule, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg336136 - (view) Author: Dylan Lloyd (majuscule) Date: 2019-02-20 19:02
``` ❯ python -c 'import pathlib; import importlib; importlib.import_module(pathlib.Path("poc.py"))' Traceback (most recent call last): File "", line 1, in File "~/.conda/envs/py3.6/lib/python3.6/importlib/__init__.py", line 117, in import_module if name.startswith('.'): AttributeError: 'PosixPath' object has no attribute 'startswith' ```
msg336137 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-02-20 19:08
This is also present in 3.7 and 3.8. I would look at it and propose a patch tomorrow.
msg336138 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2019-02-20 19:13
Thanks for the report, but importlib.import_module() doesn't accept a path of a Python module: https://docs.python.org/3/library/importlib.html#importlib.import_module So, the correct way to use the API is: import importlib importlib.import_module('poc') Whether we should explicitly reject passing a file path to import_module() is up to the importlib maintainers.
msg336139 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-02-20 19:31
I concur with Berker. Since the argument of importlib.import_module() is not a path, pathlib.Path is not valid here. It is uncommon in Python to check the type of arguments explicitly. pathlib.Path is not more special than list or tkinter.Button.
msg336141 - (view) Author: Dylan Lloyd (majuscule) Date: 2019-02-20 19:41
Whoops, yes, that of course makes sense. My mistake. Thanks!
msg336143 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-02-20 19:52
I close this issue, it's not a bug.
History
Date User Action Args
2022-04-11 14:59:11 admin set github: 80237
2019-02-20 21:01:42 berker.peksag set type: enhancementresolution: not a bug
2019-02-20 19:52:28 matrixise set status: open -> closedmessages: + nosy: + matrixise
2019-02-20 19:41:00 majuscule set status: closed -> opentype: enhancement -> (no value)resolution: not a bug -> (no value)messages: +
2019-02-20 19:31:44 serhiy.storchaka set status: open -> closedmessages: + nosy: + serhiy.storchaka
2019-02-20 19:14:06 berker.peksag set status: pending -> opennosy: + remi.lapeyre
2019-02-20 19:13:46 berker.peksag set status: open -> pendingtype: enhancementversions: - Python 3.7, Python 3.8nosy: + berker.peksag, brett.cannon, - remi.lapeyremessages: + resolution: not a bugstage: resolved
2019-02-20 19:08:54 remi.lapeyre set nosy: + remi.lapeyremessages: + versions: + Python 3.7, Python 3.8
2019-02-20 19:02:21 majuscule create