Skip to main content

flake8 plugin that checks for missing `timeout` parameters in network calls.

Project description

ci pre-commit.ci status

flake8-timeout

A flake8 plugin that checks for missing timeout parameters in network calls.

By default, the plugin checks common HTTP libraries but can be configured to track any function that accepts a timeout parameter.

installation

pip install flake8-timeout

flake8 code

Code Description
TIM100 timeout missing for request call

default tracked functions

The plugin tracks these functions by default:

  • requests.get
  • requests.post
  • requests.put
  • requests.delete
  • requests.head
  • requests.patch
  • requests.options
  • requests.request
  • urllib.request.urlopen (timeout at positional index 2)

configuration

as a pre-commit hook

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/pycqa/flake8
    rev: 7.0.0
    hooks:
    -   id: flake8
        additional_dependencies: [flake8-timeout==2.0.0]

extending the defaults

Use --timeout-extend-funcs to add custom functions while keeping the defaults:

Command line:

flake8 --timeout-extend-funcs=my_http_lib.request,custom.api.call:1

Pre-commit:

-   repo: https://github.com/pycqa/flake8
    rev: 7.0.0
    hooks:
    -   id: flake8
        additional_dependencies: [flake8-timeout==2.0.0]
        args: [--timeout-extend-funcs=my_http_lib.request,custom.api.call:1]

This will check the defaults plus your custom functions.

overriding the defaults

Use --timeout-funcs to replace the defaults entirely:

Command line:

flake8 --timeout-funcs=custom.http.get,custom.http.post:2

Pre-commit:

-   repo: https://github.com/pycqa/flake8
    rev: 7.0.0
    hooks:
    -   id: flake8
        additional_dependencies: [flake8-timeout==2.0.0]
        args: [--timeout-funcs=custom.http.get,custom.http.post:2]

This will only check the functions you specify, ignoring the defaults.

positional timeout arguments

Some functions accept timeout as a positional argument. Specify the 0-based index after a colon:

my_lib.fetch:2    # timeout is at index 2 (3rd argument)
other.call:0      # timeout is at index 0 (1st argument)

Example with positional timeout:

# my_lib.fetch(url, data, timeout)
my_lib.fetch('https://api.example.com', None, 30)  # OK - timeout at index 2
my_lib.fetch('https://api.example.com', None)      # TIM100 - missing timeout

Project details


Download files

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

Source Distribution

flake8_timeout-2.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

flake8_timeout-2.0.0-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file flake8_timeout-2.0.0.tar.gz.

File metadata

  • Download URL: flake8_timeout-2.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for flake8_timeout-2.0.0.tar.gz
Algorithm Hash digest
SHA256 27dd5e0cc0e424e03ade6652949e7cfb9badad7404e50e60d6bb29cffd75ee22
MD5 0fceaae4ae1d173ed032dd52a3fa5910
BLAKE2b-256 9a40a958614169b63f57b0eb7f4d6a8f5ae7ab45e3d8400b3ec7f45258268a34

See more details on using hashes here.

File details

Details for the file flake8_timeout-2.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_timeout-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ed8cd50dd5ee556d32d4efed2ab750218600abe81da1b99a8dbec57becf965bb
MD5 5e543a4ee3c8a190304882708e739715
BLAKE2b-256 1a46d8130db12ff5a17aada5bf915679ff39b2ff8c47fe41429dbb80ca9db964

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