[New-bugs-announce] [issue46926] runpy.run_path didn't set __package__ as describe in doc

Charlie Yan report at bugs.python.org
Fri Mar 4 19:01:39 EST 2022


New submission from Charlie Yan <yanhao.charles at gmail.com>:

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.

----------
messages: 414555
nosy: yanhao.charles
priority: normal
severity: normal
status: open
title: runpy.run_path didn't set __package__ as describe in doc
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46926>
_______________________________________


More information about the New-bugs-announce mailing list