vera-l / flake8-no-callbacks

Flake8 plugin that prohibits to use callbacks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flake8-no-callbacks

Tornado callback-argument of http-client was deprecated in tornado 5.1 and removed in version 6.0. This plugin highlights callbacks to replace them by coroutines.

The problem

Bad:

def _cb(json, response):
    if not response.error and json is not None:
        self.json.put(json)

self.get_url(
    someHost,
    '/path/to',
    data={
        'id': self.get_argument('id'),
    },
    callback=_cb,
)

Good:

result = await self.get_url(
    someHost,
    '/path/to',
    data={
        'id': self.get_argument('id'),
    },
)
if not result.failed:
    self.json.put(result.data)

Rules

  • NOC101 - Callbacks are deprecated. Use coroutines instead.

Installation

python3 setup.py istall

Usage

flake8 --select NOC101 .

my_project/pages/path/to/__init__.py:246:13: NOC101 Callbacks are deprecated. Use coroutines instead.
            self.post_url(
            ^
...

Developing

Use astpretty to see formatted ast nodes:

astpretty --no-show-offsets /dev/stdin <<< "not a == b"

Run tests:

pytest -vv tests

About

Flake8 plugin that prohibits to use callbacks


Languages

Language:Python 100.0%