Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Avoid polluting the namespace by doing "import *" #115

Open
0xHericles opened this issue Jun 21, 2021 · 3 comments
Open

Avoid polluting the namespace by doing "import *" #115

0xHericles opened this issue Jun 21, 2021 · 3 comments
Assignees
Labels

Comments

@0xHericles
Copy link
Owner

Description

Importing a module using import * may unintentionally pollute the global namespace if the module does not define __all__

When you import a module using from xxx import * all public names defined in the module are imported and bound in the local namespace of the import statement. The public names are determined by checking the all variable for the module. If all is not defined then all names within the module that do not start with an underscore character are imported. This pollutes the current namespace with names that are not part of the public API for the module.

70 | from .routes import *
71 | from .events import *
72 | 
73 | app.register_blueprint(http, url_prefix=r"")

Recommendation

There are two ways to address this problem:

  • where possible, modify the module being imported from and define all to restrict the names to be imported
  • otherwise, explicitly import the values that you need.
@0xHericles 0xHericles changed the title Avoid polluting the namespace by doing import * Avoid polluting the namespace by doing "import *" Jun 21, 2021
@Zkarvx
Copy link
Contributor

Zkarvx commented Jun 21, 2021

Hi @hericlesme,
can i work on this issue ?

@0xHericles
Copy link
Owner Author

@Zkarvx of course! :D

@Zkarvx
Copy link
Contributor

Zkarvx commented Jun 22, 2021

#116

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants