[New-bugs-announce] [issue30337] Vague wording of pkgutil.walk_packages parameter 'prefix'

Sam Silberstein report at bugs.python.org
Wed May 10 16:49:49 EDT 2017


New submission from Sam Silberstein:

Hi there! 

This is my first submission to the bug tracker, so I apologize if I'm missing some formatting here.

I've found what's either vague documentation for the 'prefix' parameter of `pgkutil.walk_packages` or a bug. The method implies that it will only import submodules of the provided path, but if the prefix parameter is not filled, this method will import a module with the same name from outside the path -- so long as it exists in `sys.modules`. I'm unsure if this is due to the documentation not specifying that prefix should always be used when path is set, or if this is a bug (I can provide a fix if it's a bug).

Steps to reproduce:

Create a directory with a nested package with the same name as a package outside that directory, e.g.:

|_ test1
  |_ __init__.py
  |_ should_not_be_included.py
|_ test2
  |_ test1
    |_ __init__.py
    |_ test1
      |_ __init__.py
      |_ should_be_included.py

`list(pkgutil.walk_packages('test2'))` will contain 'should_not_be_included.py' instead of 'should_be_included.py'.

Thank you!

Sam Silberstein

----------
assignee: docs at python
components: Documentation
messages: 293453
nosy: docs at python, smsilb
priority: normal
severity: normal
status: open
title: Vague wording of pkgutil.walk_packages parameter 'prefix'
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30337>
_______________________________________


More information about the New-bugs-announce mailing list