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

Metadata

Release files for flake8-caller-callee-order 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-caller-callee-order 0.2.0
File Size Uploaded
flake8_caller_callee_order-0.2.0.tar.gz 28.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-caller-callee-order 0.2.0
File Interpreter ABI Platform
flake8_caller_callee_order-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.0 kB

Release files / flake8_caller_callee_order-0.2.0.tar.gz

Download URL flake8_caller_callee_order-0.2.0.tar.gz
Size 28.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5e6c97f8968c667d04b700c98707dd61504818ce008d1cdfb614d4fb586fd4a9
BLAKE2b-256 checksum
How to use checksums
fef1619dfae87d810060d27609b7f38a146be3f849315f8c6b02d1d1c9095a07
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / flake8_caller_callee_order-0.2.0-py3-none-any.whl

Download URL flake8_caller_callee_order-0.2.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0df7d3b959d83aad8afebb66d9cb3c7cb7a6f3dff2675ab22dd70f1cd9872b7a
BLAKE2b-256 checksum
How to use checksums
a1fd4032c2f96069f647f531e5e0d12cc7fe85321e889005c8feb15a5fbc3b6a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release 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