Skip to main content

pylint-google-style

Pylint plugins that enforce two import rules from the Google Python Style Guide:

  1. Import modules, not symbols — prefer from a.b import c and reference c.Symbol, rather than from a.b.c import Symbol.
  2. Use absolute imports, not relative imports — prefer from mypackage.utils import helper over from ..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

pylint_google_style-0.1.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylint_google_style-0.1.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file pylint_google_style-0.1.1.tar.gz.

File metadata

  • Download URL: pylint_google_style-0.1.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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

Hashes for pylint_google_style-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3e4578d1769e6f600ff1990a56f546bc02aa874fb77e6015be973380b3b5d7f0
MD5 fcf21ca19db9d785de9c5e7d33893627
BLAKE2b-256 8c1c5c49fd4083def2279b3dd3188376b2a9bb7b693189d3aa183d00a0b5d91d

See more details on using hashes here.

File details

Details for the file pylint_google_style-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pylint_google_style-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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

Hashes for pylint_google_style-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0e096446c5ab888f9708eae92e007ac823a7aa99b9a8a14d0998e534371b2cc
MD5 c6d22d102c7dc9e6967824bc808a7370
BLAKE2b-256 2d62e0247e17890fc0b7754397d9db3846ff110439e58cd6ea6ca110c1324c57

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page