Shadowing stdlib module inspection¶
Reports project modules that shadow Python standard library modules, such as random.py, logging.py, or json.py.
Python searches the script or current directory before the standard library. A project file with the same name as a standard library module can make ordinary application code, dependencies, tests, and debugging sessions import the project file instead of the intended stdlib module.
How to invoke¶
Enable the inspection, place the caret on the highlighted module name, then use ⌥⏎ / Alt+Enter -> "Rename file".
Example¶
Rename the file to a non-stdlib name:
What it supports¶
- Project Python files whose base name matches a Python standard library module.
- The standard
__main__.pyentrypoint, which is ignored. - Rename confirmation when a file is renamed to a standard library module name.
Notes¶
- The inspection only runs on your own project files, not library or stub sources.
- The feature is gated by the File name shadows a Python standard library module setting under Settings | BetterPy | Code Quality & Safety | Code Inspections and is enabled by default.