Issue36056
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 "<string>", line 1, in <module>
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) * ![]() |
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) * ![]() |
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) * ![]() |
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: enhancement resolution: not a bug |
| 2019-02-20 19:52:28 | matrixise | set | status: open -> closed |
| 2019-02-20 19:41:00 | majuscule | set | status: closed -> open type: enhancement -> (no value) resolution: not a bug -> (no value) messages: + msg336141 |
| 2019-02-20 19:31:44 | serhiy.storchaka | set | status: open -> closed messages:
+ msg336139 |
| 2019-02-20 19:14:06 | berker.peksag | set | status: pending -> open nosy: + remi.lapeyre |
| 2019-02-20 19:13:46 | berker.peksag | set | status: open -> pending type: enhancement messages:
+ msg336138 |
| 2019-02-20 19:08:54 | remi.lapeyre | set | nosy:
+ remi.lapeyre messages:
+ msg336137 |
| 2019-02-20 19:02:21 | majuscule | create | |
