nbqa
This linter has been disabled in this version
Disabled reason: Failing test cases, to fix before enabling again
nbqa + mypy provides static type checking for Jupyter notebooks.
nbqa (NoteBook QA) runs standard Python linters on Jupyter notebooks by extracting code cells and running the linter on them. Combined with mypy, it brings static type checking to notebook development.
Key features:
- Type Checking in Notebooks: Catch type errors in notebook cells before execution
- Cell-Aware Errors: Error messages reference correct cell and line numbers
- Mypy Integration: Uses your existing mypy configuration
- Supports Complex Types: Handles generics, protocols, type inference, etc.
- Gradual Typing: Add type hints incrementally to notebooks
- IDE Integration: Works with Jupyter Lab, VS Code, and other notebook editors
Common use cases: - Type-check data science notebooks before production deployment - Catch type errors in ML model training code - Ensure type consistency across notebook projects - Validate notebook code in CI/CD pipelines
Note: This linter only checks .ipynb files. Use PYTHON_MYPY for .py and .pyi files.
nbqa documentation
- Visit Official Web Site
- If custom
.mypy.iniconfig file isn't found, .mypy.ini will be used
- If custom
- See Index of problems detected by nbqa
Configuration in MegaLinter
- Enable nbqa by adding
PYTHON_NBQA_MYPYin ENABLE_LINTERS variable - Disable nbqa by adding
PYTHON_NBQA_MYPYin DISABLE_LINTERS variable
| Variable | Description | Default value |
|---|---|---|
| PYTHON_NBQA_MYPY_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
| PYTHON_NBQA_MYPY_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
| PYTHON_NBQA_MYPY_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
| PYTHON_NBQA_MYPY_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
| PYTHON_NBQA_MYPY_CLI_LINT_MODE | Override default CLI lint mode - file: Calls the linter for each file- list_of_files: Call the linter with the list of files as argument- project: Call the linter from the root of the project |
list_of_files |
| PYTHON_NBQA_MYPY_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".ipynb"] |
| PYTHON_NBQA_MYPY_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
Include every file |
| PYTHON_NBQA_MYPY_PRE_COMMANDS | List of bash commands to run before the linter | None |
| PYTHON_NBQA_MYPY_POST_COMMANDS | List of bash commands to run after the linter | None |
| PYTHON_NBQA_MYPY_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling PYTHON_NBQA_MYPY and its pre/post commands | None |
| PYTHON_NBQA_MYPY_CONFIG_FILE | nbqa configuration file name Use LINTER_DEFAULT to let the linter find it |
.mypy.ini |
| PYTHON_NBQA_MYPY_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
| PYTHON_NBQA_MYPY_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
| PYTHON_NBQA_MYPY_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
| PYTHON_NBQA_MYPY_CLI_EXECUTABLE | Override CLI executable | ['nbqa'] |
MegaLinter Flavors
This linter is available in the following flavors
| Flavor | Description | Embedded linters | Info | |
|---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 134 |
Behind the scenes
How are identified applicable files
- File extensions:
.ipynb
How the linting is performed
- nbqa is called once with the list of files as arguments (
list_of_filesCLI lint mode)
Example calls
nbqa mypy myfile.ipynb
nbqa mypy --config-file .mypy.ini myfile.ipynb
Installation on mega-linter Docker image
- Dockerfile commands :
# renovate: datasource=pypi depName=nbqa
ARG PIP_NBQA_VERSION=1.9.1
# renovate: datasource=pypi depName=mypy
ARG PIP_MYPY_VERSION=1.19.1
ENV MYPY_CACHE_DIR=/tmp
- PIP packages (Python):
