This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: runpy.run_path didn't set __package__ to None as describe in doc
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: yanhao.charles
Priority: normal Keywords:

Created on 2022-03-05 00:01 by yanhao.charles, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg414555 - (view) Author: Charlie Yan (yanhao.charles) Date: 2022-03-05 00:01
As described in the doc: https://docs.python.org/3.8/library/runpy.html#runpy.run_path

> If the supplied path directly references a script file (whether as source or as precompiled byte code), then __file__ will be set to the supplied path, and __spec__, __cached__, __loader__ and __package__ will all be set to None.

But:
```
$ cat a.py
print(f'{__name__ = }')
print(f'{__package__ = }')

$ cat b.py
import runpy
runpy.run_path('a.py')

$ python3 b.py
__name__ = '<run_path>'
__package__ = ''
```

`__package__` is not set to None as in the doc.
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91082
2022-03-08 14:41:05yanhao.charlessettype: behavior
components: + Library (Lib)
2022-03-05 00:03:26yanhao.charlessettitle: runpy.run_path didn't set __package__ as describe in doc -> runpy.run_path didn't set __package__ to None as describe in doc
2022-03-05 00:01:39yanhao.charlescreate