Skip to content

Commit

Permalink
Merge pull request #54 from python-discord/dev-next
Browse files Browse the repository at this point in the history
Release v1.1.3
  • Loading branch information
sco1 authored Dec 20, 2019
2 parents b3cdb41 + 9ef76d1 commit 704fab2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 39 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (`<major>`.`<minor>`.`<patch>`)

## [v1.1.3]
### Fixed
* Add missing classifier test cases for POSONLYARGS
* Re-add the `tree` argument to the checker so flake8 identifies the plugin as needing to run

## [v1.1.2]
### Changed
* Request source from `flake8` as lines of code rather than parsing it from the requested filename ourselves, allowing for proper parsing of `stdin` inputs
Expand Down
2 changes: 0 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ tox = "~=3.14"
lint = "flake8"
check_metadata = "python setup.py --quiet check --metadata --strict"
precommit = "pre-commit install"
test = "tox"
coverage = "pytest --cov=flake8_annotations --cov=testing testing/ --cov-branch --cov-report term-missing"
35 changes: 10 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# flake8-annotations
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-annotations)
![PyPI](https://img.shields.io/pypi/v/flake8-annotations)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-annotations)](https://pypi.org/project/flake8-annotations/)
[![PyPI](https://img.shields.io/pypi/v/flake8-annotations)](https://pypi.org/project/flake8-annotations/)
[![Build Status](https://dev.azure.com/python-discord/Python%20Discord/_apis/build/status/python-discord.flake8-annotations?branchName=master)](https://dev.azure.com/python-discord/Python%20Discord/_build/latest?definitionId=16&branchName=master)
[![Discord](https://img.shields.io/discord/267624335836053506?color=%237289DA&label=Python%20Discord&logo=discord&logoColor=white)](https://discord.gg/2B963hn)


`flake8-annotations` is a plugin for [Flake8](http://flake8.pycqa.org/en/latest/) that detects the absence of [PEP 3107-style](https://www.python.org/dev/peps/pep-3107/) function annotations and [PEP 484-style](https://www.python.org/dev/peps/pep-0484/#type-comments) type comments (see: [Caveats](#Caveats-for-PEP-484-style-Type-Comments)).

What this won't do: Check variable annotations (see: [PEP 526](https://www.python.org/dev/peps/pep-0526/)), respect stub files, or replace [mypy's](http://mypy-lang.org/) static type checking.
What this won't do: Check variable annotations (see: [PEP 526](https://www.python.org/dev/peps/pep-0526/)), respect stub files, or replace [mypy](http://mypy-lang.org/).

## Installation

Expand All @@ -23,7 +23,7 @@ You can verify it's being picked up by invoking the following in your shell:

```bash
$ flake8 --version
3.7.8 (flake8-annotations: 1.1.2, mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.4 on Darwin
3.7.8 (flake8-annotations: 1.1.3, mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.4 on Darwin
```

## Table of Warnings
Expand Down Expand Up @@ -123,32 +123,17 @@ A [pre-commit](https://pre-commit.com) installation script and configuration is
$ pipenv run precommit
```

### Testing
A [pytest](https://docs.pytest.org/en/latest/) suite is provided for testing across multiple Python environments via [tox](https://github.com/tox-dev/tox/):
or

```bash
$ pipenv run test
$ pre-commit install
```

### Coverage
Test coverage is provided by [pytest-cov](https://github.com/pytest-dev/pytest-cov) via a pipenv script:
### Testing & Coverage
A [pytest](https://docs.pytest.org/en/latest/) suite is provided, with coverage reporting from [pytest-cov](https://github.com/pytest-dev/pytest-cov). A [tox](https://github.com/tox-dev/tox/) configuration is provided to test across all supported versions of Python. Testing will be skipped for Python versions that cannot be found.

```bash
$ pipenv run coverage
$ tox
```

When running via pipenv, details on missing coverage is provided in the report to allow the user to generate additional tests for full coverage.

e.g.

```
----------- coverage: platform win32, python 3.7.4-final-0 -----------
Name Stmts Miss Branch BrPart Cover Missing
-------------------------------------------------------------------------------
flake8_annotations\__init__.py 108 0 38 0 99% 164
flake8_annotations\checker.py 57 0 30 0 100%
flake8_annotations\enums.py 15 0 0 0 100%
flake8_annotations\error_codes.py 85 0 0 0 100%
-------------------------------------------------------------------------------
TOTAL 265 0 68 0 99%
```
Details on missing coverage, including in the test suite, is provided in the report to allow the user to generate additional tests for full coverage.
2 changes: 1 addition & 1 deletion flake8_annotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

PY_GTE_38 = False

__version__ = "1.1.2"
__version__ = "1.1.3"

AST_ARG_TYPES = ("args", "vararg", "kwonlyargs", "kwarg")
if PY_GTE_38:
Expand Down
3 changes: 2 additions & 1 deletion flake8_annotations/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class TypeHintChecker:
name = "flake8-annotations"
version = __version__

def __init__(self, lines: List[str]):
def __init__(self, tree: ast.Module, lines: List[str]):
# Request `tree` in order to ensure flake8 will run the plugin, even though we don't use it
# Request `lines` here and join to allow for correct handling of input from stdin
self.lines = lines
self.tree = self.get_typed_tree("".join(lines)) # flake8 doesn't strip newlines
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
name="flake8-annotations",
license="MIT",
version="1.1.2",
version="1.1.3",
description="Flake8 Type Annotation Checks",
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
11 changes: 5 additions & 6 deletions testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def parse_source(src: str) -> Tuple[ast.Module, List[str]]:
def check_source(src: str) -> Generator[Error, None, None]:
"""Helper for generating linting errors from the provided source code."""
_, lines = parse_source(src)
checker_instance = TypeHintChecker(lines)
checker_instance = TypeHintChecker(None, lines)

return checker_instance.run()

Expand All @@ -43,10 +43,9 @@ def functions_from_source(src: str) -> List[Function]:

def find_matching_function(func_list: Iterable[Function], match_name: str) -> Optional[Function]:
"""
Iterate over a list of Function objects & find the matching named function.
Iterate over a list of Function objects & find the first matching named function.
If no function is found, this returns None
Due to the definition of the test cases, this should always return something, but there is no
protection if a match isn't found & will raise an `IndexError`.
"""
for function in func_list:
if function.name == match_name:
return function
return [function for function in func_list if function.name == match_name][0]
14 changes: 11 additions & 3 deletions testing/test_cases/classifier_object_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,21 @@ class AT(NamedTuple):
AT(True, False, ClassDecoratorType.CLASSMETHOD, AnnotationType.ARGS): error_codes.TYP001,
AT(True, True, ClassDecoratorType.STATICMETHOD, AnnotationType.ARGS): error_codes.TYP001,
AT(True, False, ClassDecoratorType.STATICMETHOD, AnnotationType.ARGS): error_codes.TYP001,
AT(True, False, None, AnnotationType.ARGS): error_codes.TYP001,
AT(False, True, None, AnnotationType.ARGS): error_codes.TYP001,
AT(False, False, None, AnnotationType.ARGS): error_codes.TYP001,
AT(True, False, ClassDecoratorType.CLASSMETHOD, AnnotationType.KWONLYARGS): error_codes.TYP001,
AT(True, True, ClassDecoratorType.STATICMETHOD, AnnotationType.KWONLYARGS): error_codes.TYP001,
AT(True, False, ClassDecoratorType.STATICMETHOD, AnnotationType.KWONLYARGS): error_codes.TYP001,
AT(True, False, ClassDecoratorType.CLASSMETHOD, AnnotationType.POSONLYARGS): error_codes.TYP001,
AT(True, True, ClassDecoratorType.STATICMETHOD, AnnotationType.POSONLYARGS): error_codes.TYP001,
AT(
True, False, ClassDecoratorType.STATICMETHOD, AnnotationType.POSONLYARGS
): error_codes.TYP001,
AT(True, False, None, AnnotationType.ARGS): error_codes.TYP001,
AT(False, True, None, AnnotationType.ARGS): error_codes.TYP001,
AT(False, False, None, AnnotationType.ARGS): error_codes.TYP001,
AT(True, False, None, AnnotationType.KWONLYARGS): error_codes.TYP001,
AT(False, True, None, AnnotationType.KWONLYARGS): error_codes.TYP001,
AT(False, False, None, AnnotationType.KWONLYARGS): error_codes.TYP001,
AT(True, False, None, AnnotationType.POSONLYARGS): error_codes.TYP001,
AT(False, True, None, AnnotationType.POSONLYARGS): error_codes.TYP001,
AT(False, False, None, AnnotationType.POSONLYARGS): error_codes.TYP001,
}

0 comments on commit 704fab2

Please sign in to comment.