Documentation of `pkgutil.walk_packages`

Hello, this is my first post here, so I’m not sure if it is the right communication channel to get feedback. I noticed that the function pkgutil.walk_packages documentation says:

Yields ModuleInfo for all modules recursively on path , or, if path is None , all accessible modules.

Emphasis o the modules recursively mine. The thing is that this only works recursively if the correct prefix value is provided, which is not super clear from the docs:

prefix is a string to output on the front of every module name on output.

For example:

>>> import pkgutil
>>> len(list(pkgutil.walk_packages(['/usr/lib64/python3.10/xml/'])))
4
>>> len(list(pkgutil.walk_packages(['/usr/lib64/python3.10/xml/'], '')))
4
>>> len(list(pkgutil.walk_packages(['/usr/lib64/python3.10/xml/'], 'xml.')))
21

So I’d like to fix that, I’m not sure what is the best approach here, changing the function’s behavior (which would be a backwards incompatible change), or updating the docs to clarify this.

Thanks

This would be the simplest approach, please could you open an issue on the CPython repo? If you have a proposed wording please also open a pull request, there is some guidance on the DevGuide.

A

Thanks for the reply, issue created: Documentation of `pkgutil.walk_packages` is unclear · Issue #92229 · python/cpython · GitHub

1 Like