Skip to main content

flake8-caller-callee-order

This repo includes a flake8 plugin that enforces local definition/reference order:

Installation

pip install flake8-caller-callee-order

Usage

uv run flake8 path/to/file.py

For example, with the default callee-before-caller order, this is reported:

def main():
    helper()


def helper():
    print("helper")
CCO001 `main` references `helper`, but `helper` is defined later at line 5

By default, caller-callee-order = callee-before-caller, and CCO001 is emitted when a local definition references another local definition that is defined later in the same module scope. It also checks method references within class scopes by method name, and it recursively checks nested definitions inside functions and classes.

Supported definitions are:

  • def
  • async def
  • class
  • assignments like name = value
  • annotated assignments like name: type = value
  • imports like import module and from module import name

For now it checks simple local references like helper() or CONFIG, plus method references like self.helper() and cls.helper() inside classes. Attribute bases are still checked when they are local definitions, so Service.make() can report a later-defined Service, but arbitrary attribute resolution such as module.helper is not resolved to imported module members. Class attributes are not ordered yet.

Nested function scopes check nested def, async def, and class definitions. Local bindings such as arguments, assignments, imports, loop targets, context-manager targets, exception names, walrus targets, and augmented assignment targets are treated as local names so they do not produce false positives against outer definitions.

Lambdas and comprehensions are skipped conservatively until their binding scopes are modeled.

See DESIGN.md for the resolver design and intentionally deferred edge cases.

To require callers before their callees instead, configure Flake8 with:

[flake8]
caller-callee-order = caller-before-callee

Development

uv run flake8 .
uv run pytest
uv run ruff check
uv run ruff format
uv run mypy

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8_caller_callee_order-0.2.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

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

flake8_caller_callee_order-0.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file flake8_caller_callee_order-0.2.0.tar.gz.

File metadata

  • Download URL: flake8_caller_callee_order-0.2.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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 flake8_caller_callee_order-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5e6c97f8968c667d04b700c98707dd61504818ce008d1cdfb614d4fb586fd4a9
MD5 26f95d7eb93f592940761463f9fc43a6
BLAKE2b-256 fef1619dfae87d810060d27609b7f38a146be3f849315f8c6b02d1d1c9095a07

See more details on using hashes here.

File details

Details for the file flake8_caller_callee_order-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: flake8_caller_callee_order-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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 flake8_caller_callee_order-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0df7d3b959d83aad8afebb66d9cb3c7cb7a6f3dff2675ab22dd70f1cd9872b7a
MD5 0572a942eabd733790f3629d6ae98b1f
BLAKE2b-256 a1fd4032c2f96069f647f531e5e0d12cc7fe85321e889005c8feb15a5fbc3b6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page