pylint-google-style
Pylint plugins that enforce two import rules from the Google Python Style Guide:
- Import modules, not symbols — prefer
from a.b import cand referencec.Symbol, rather thanfrom a.b.c import Symbol. - Use absolute imports, not relative imports — prefer
from mypackage.utils import helperoverfrom ..utils import helper.
Google publishes an official
pylintrc alongside the style
guide, but stock pylint has no checkers for these two import rules, so they go
unenforced. This package fills that gap: use it together with Google's
pylintrc, not instead of it.
Installation
uv add --dev pylint-google-style
# or
pip install pylint-google-style
Usage
Start from Google's official pylintrc as your baseline:
curl -O https://google.github.io/styleguide/pylintrc
Then enable these checkers by adding the plugins to that .pylintrc:
[MAIN]
load-plugins =
pylint_google_style.import_module,
pylint_google_style.relative_import
Or on the command line:
pylint --load-plugins=pylint_google_style.import_module,pylint_google_style.relative_import your_package/
Checks
| Code | Symbol | Description |
|---|---|---|
C9001 |
import-symbol-not-module |
A symbol was imported from a module; import the module instead. |
C9003 |
import-symbol-not-package |
A symbol was imported from a top-level package; import the package. |
C9002 |
relative-import |
A relative import was used; use an absolute import instead. |
W9001 |
import-module-unresolvable |
The parent module could not be resolved, so the import was not checked. |
__init__.py files are exempt from both checkers, since re-exporting symbols
there is idiomatic.
Example
# flagged (C9001): symbol imported from a module
from os.path import join
# preferred
from os import path
path.join(...)
# flagged (C9002): relative import
from ..utils import helper
# preferred
from mypackage.utils import helper
Configuration
The import-module checker accepts additional modules to exempt from the
symbol-vs-module rule (on top of the built-in exemptions for typing-related
modules such as typing, typing_extensions, collections.abc, and
__future__):
[IMPORT-MODULE]
import-module-exceptions =
numpy,
pandas
Development
uv sync
uv run pytest # run tests
uv run ruff check . # lint
uv run ruff format --check . # formatting
License
MIT © Zhitao Gong
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylint_google_style-0.1.2.tar.gz.
File metadata
- Download URL: pylint_google_style-0.1.2.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81c2b298c7bf4eb69b827810dc7b2c07a230401c469fb53adf7d41c2f5fbf1fa
|
|
| MD5 |
a2c9d709f4772a109b86a995db36c50c
|
|
| BLAKE2b-256 |
58a632b69896b203c223672c40cb1aac10e038eb7df53a04e12eb2bc4829d2a2
|
File details
Details for the file pylint_google_style-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pylint_google_style-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c4aa2ea9e69a31b79bbbd194011ec357fc2db318102df4fc71ce233cd8632b6
|
|
| MD5 |
06b03ac0c4f418aaf773f7b6d07af1e4
|
|
| BLAKE2b-256 |
3969bdc72416061b2a86cc2d3feecdc4c29682df9c0bad676b8bf96be3191d50
|