Skip to main content

A flake8 plugin to detect return None (-> None) type hints.

Project description

flake8-noreturn

pre-commit.ci status Maintainability

Flake8 plugin to check for using -> None: type hint for return type. Helps to replace them with -> NoRetun type hint from typing.

Why to use NoReturn type hint?

Using NoReturn type hint:

  • is more explicit and helps to avoid confusion with None value,
  • helps to avoid bugs when using None as a default value for function arguments.
  • helps mypy to detect unreachable code

Installation

Use pip to install the package:

$ pip3 install flake8-noreturn

Usage

$ flake8 .

to select only flake8-noreturn errors:

$ flake8 --select NR .

Rules

Currently, the plugin checks implements only one rule:

NR001 Using -> None. Indicates usage of -> None: type hint for return type.

Examples:

def foo() -> None:
    pass

will raise NR001.

from typing import NoReturn

def foo() -> NoReturn:
    pass

will not raise NR001.

def foo() -> tuple[int, None]:
    return 2, None

will not raise NR001.

Related Projects

There is a flake8-no-types which was a heavy inspiration for this project.

Credits

Thank you adamchainz for the inspiring article and the flake8-no-types which helped me to create this plugin.

License

MIT © Krystian Safjan.

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_noreturn-1.0.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

flake8_noreturn-1.0.1-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

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