Mailing List Archive

importlib changes from py3.7 to py3.8
With python3.7 I'm able to use

_module = importlib.import_module('app.plugins.plugin_dir.plugin_name')

succesfully but with python 3.8 this results in

File "D:\ProgramData\Python\Python38_64\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 779, in exec_module
File "<frozen importlib._bootstrap_external>", line 916, in get_code
File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes

Any idea what happened here?

Thank you
Eren
--
https://mail.python.org/mailman/listinfo/python-list
Re: importlib changes from py3.7 to py3.8 [ In reply to ]
Seems I've missed that __init__.py's aren't allowed to be empty anymore.
Adding a single # solved the issue.

Eren
--
https://mail.python.org/mailman/listinfo/python-list
Re: importlib changes from py3.7 to py3.8 [ In reply to ]
On 19/09/20 7:51 am, Eko palypse wrote:
> ValueError: source code string cannot contain null bytes
>
> Any idea what happened here?

> Seems I've missed that __init__.py's aren't allowed to be empty anymore.
> Adding a single # solved the issue.

I just tried importing a package with an empty __init__.py in
Python 3.8 and there was no problem:

% ls -l empty
total 0
-rw-r--r-- 1 greg staff 0 20 Sep 12:00 __init__.py
% python3
Python 3.8.2 (default, Mar 23 2020, 11:36:18)
[Clang 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import empty
>>>

It looks more like the file in question wasn't completely empty,
but had a null character in it for some reason. I expect that if
you re-saved it as truly empty it would work. If not, you should
probably report it as a bug.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
Re: importlib changes from py3.7 to py3.8 [ In reply to ]
Hello Greg,
thank you for your answer. I have checked it twice and the file is really
empty.
I even opened it with a hex editor - no content.
BUT in order to create a bug ticket I tried to make a mcve and I didn't
succeed.
I copied the function (load_plugins) 1 to 1, but outside my program it
works as it should.
So it seems that something inside my application is causing this problem.
Hmm ... Fortunately this is a pure python application so debugging should
lead to enlightenment. :-)

Thx
Eren

Am So., 20. Sept. 2020 um 02:06 Uhr schrieb Greg Ewing <
greg.ewing@canterbury.ac.nz>:

> On 19/09/20 7:51 am, Eko palypse wrote:
> > ValueError: source code string cannot contain null bytes
> >
> > Any idea what happened here?
>
> > Seems I've missed that __init__.py's aren't allowed to be empty anymore.
> > Adding a single # solved the issue.
>
> I just tried importing a package with an empty __init__.py in
> Python 3.8 and there was no problem:
>
> % ls -l empty
> total 0
> -rw-r--r-- 1 greg staff 0 20 Sep 12:00 __init__.py
> % python3
> Python 3.8.2 (default, Mar 23 2020, 11:36:18)
> [Clang 8.1.0 (clang-802.0.42)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import empty
> >>>
>
> It looks more like the file in question wasn't completely empty,
> but had a null character in it for some reason. I expect that if
> you re-saved it as truly empty it would work. If not, you should
> probably report it as a bug.
>
> --
> Greg
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list