Giter Site home page Giter Site logo

flake8-annotations-coverage's Introduction

flake8-annotations-coverage

Build Status Maintainability Test Coverage

An extension for flake8 to report on files with a lot of code without type annotations.

This is mostly useful when you add type annotations to existing large codebase and want to know if new code in annotated modules is annotated.

Minimal annotations coverage percentage for each file can be configured via --min-coverage-percents option, default is 75.

Function is treated as annotated if it has annotation for at least one argument or return type. This is enough for mypy to threat the function not as dynamically typed.

Installation

pip install flake8-annotations-coverage

Example

Sample file:

# test.py

def annotated_function(some_arg: int):
    pass


def unannotated_function():
    pass

Usage:

$ flake8 test.py
test.py:0:1: TAE001 too few type annotations

Error codes

Error code Description
TAE001 Too few type annotations in file

Contributing

We would love you to contribute to our project. It's simple:

  1. Create an issue with bug you found or proposal you have. Wait for approve from maintainer.
  2. Create a pull request. Make sure all checks are green.
  3. Fix review comments if any.
  4. Be awesome.

Here are useful tips:

flake8-annotations-coverage's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flake8-annotations-coverage's Issues

Add "--ignore-untyped" option

I have a file with several django views, which are not typed at all.
This plugin raises a violation for it.

So, my feature request is to create "--ignore-untyped" option that will suppress warning for files that are not typed at all.

Add annotations coverage to error message

Is your feature request related to a problem? Please describe.
Unable to find out current annotation coverage when receiving an error message

Describe the solution you'd like
Print the current coverage percentage in an error message

Make this plugin more flexible

I am not sure how exactly we can achieve that, but here's my problem:

# some.py

def untyped(arg):
    ...

def typed(arg: int) -> int:
    ...

As you can see the ratio of typed/untyped is 50/50 in this case. And I only have two functions here.
But, this plugin reports this file as invalid.

What have I tried?

  1. Reducing the global setting of typed code, but that is bad for my other files and overall quality. So, I won't do that
  2. Ignore this file in the setup.cfg, this does not work as well. Since, now I allow all other functions in this module to be untyped. That's not what I want.

What I seek is a some kind of setting to resolve this situation: like "Too few items to analyse" or similar.

Add an intergation test

It is a good practice to use Popen('flake8 --select=YOURCODES') and assert the results.
It saved me multiple times.

Currently I have found only unit tests.

Ignore warnings per file, per line

Is there an ability to ignore TAE001 per file from within the file, or is this something only done in the FLAKE8 configuration?
Using noqa doesn't seem to ignore the warning.

As some devs may not want to change the .flake8 config files would suggest having both options if possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.