PK!E\2 2 flake8_type_annotations.py# -*- coding: utf-8 -*- import tokenize from typing import Generator, Sequence, Tuple import pkg_resources from pycodestyle import STARTSWITH_DEF_REGEX pkg_name = 'flake8-type-annotations' #: We store the version number inside the `pyproject.toml`: pkg_version: str = pkg_resources.get_distribution(pkg_name).version CORRECT_PATTERN = ' {0} ' EQUAL = '=' ARROW = '->' def _get_boundaries( tokens: Sequence[tokenize.TokenInfo], index: int, ) -> Tuple[int, int]: _, previous_end = tokens[index - 1].end _, next_start = tokens[index + 1].start return previous_end, next_start def _count_parens(token: tokenize.TokenInfo) -> int: if token.exact_type in (tokenize.LPAR, tokenize.LSQB): return 1 if token.exact_type in (tokenize.RPAR, tokenize.RSQB): return -1 return 0 def _validate_parameters( tokens: Sequence[tokenize.TokenInfo], ) -> Generator[Tuple[int, int], None, None]: parens = 0 annotated_func_arg = False for index, token in enumerate(tokens): parens += _count_parens(token) if token.exact_type == tokenize.COLON and parens == 1: annotated_func_arg = True elif token.exact_type == tokenize.COMMA and parens == 1: annotated_func_arg = False if annotated_func_arg and token.exact_type == tokenize.EQUAL: previous_end, next_start = _get_boundaries(tokens, index) if next_start - previous_end < len(CORRECT_PATTERN.format(EQUAL)): yield token.start def _validate_return_type( tokens: Sequence[tokenize.TokenInfo], ) -> Generator[Tuple[int, int], None, None]: for index, token in enumerate(tokens): if token.string == ARROW: # there's no operator for `->` in tokenize previous_end, next_start = _get_boundaries(tokens, index) if next_start - previous_end < len(CORRECT_PATTERN.format(ARROW)): yield token.start class Checker(object): """Flake8 plugin to find incorrect type annotation styles.""" name = pkg_name version = pkg_version T800 = ( 'T800: Missing spaces between parameter ' 'annotation and default value' ) T801 = 'T801: Missing spaces in return type annotation' def __init__( self, logical_line: str, tokens: Sequence[tokenize.TokenInfo], ) -> None: """ Creates new checker instance. We need both tree and tokenize sequence, since it is sometimes easier to get the information from ``ast`` and sometimes it is easier to get the information from ``tokenize`` sources. """ self.logical_line = logical_line self.tokens = tokens def __iter__(self) -> Generator[Tuple[Tuple[int, int], str], None, None]: """Called by ``flake8`` on each logical line in a file.""" if STARTSWITH_DEF_REGEX.match(self.logical_line): for offset in _validate_parameters(self.tokens): yield offset, self.T800 for offset in _validate_return_type(self.tokens): yield offset, self.T801 PK!H=e378flake8_type_annotations-0.1.0.dist-info/entry_points.txtNINK(I+ϋ ƗT'$3RSPK!#)///flake8_type_annotations-0.1.0.dist-info/LICENSEMIT License Copyright (c) 2018 Nikita Sobolev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H_zTT-flake8_type_annotations-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]n0H*J>mlcAPK!H= 0flake8_type_annotations-0.1.0.dist-info/METADATAV{o6CF#ͣ鄹؎ogk$Zf,*IVdR0,w=yK5 & -ꐘ:x}o,\hCo]A4q!X LDHbҔkl +ET+S+!!hj(\틸'":C0r·HZx%Uu1' VTD"kJ"3z*;l4Žն,rsmS4_S&z>TOwǿQMK:Hb!%Uqp s&Yu;,M A Cz`7  ޕ? GwnH1Q'#b:.dAk@!boD ӗ^,q#1 a(&zA$݉cI"U[8"HM_vJ%Xlr eɜGU ߷R„@9dCS{DiОۇЗ/_LQ 9B w$q&y^WDͯ(~`[ŕAI}:!0Vc,t{G*;ÒT)Xi=8"0CJ!ULey]#7OQs =9ַlrΠW*9:1[%"^)IFHN).PW~ۿ8q9/PK!H -4(.flake8_type_annotations-0.1.0.dist-info/RECORDͻv0oH *>`ᨀ"|}'Hwu˲g^T%f~N-}I.n>)vo2 W HI?9(BR0>-ʬJKtq]%g!QA.}MDZDVMȟzo7G~Ɲ'"hQ.>c.LE ~!a3Y(T=Ln=lZE<&W;:\.>( Ll43>378\'GgȎ 2עm;jZtMmb&PK!E\2 2 flake8_type_annotations.pyPK!H=e378j flake8_type_annotations-0.1.0.dist-info/entry_points.txtPK!#)/// flake8_type_annotations-0.1.0.dist-info/LICENSEPK!H_zTT-oflake8_type_annotations-0.1.0.dist-info/WHEELPK!H= 0flake8_type_annotations-0.1.0.dist-info/METADATAPK!H -4(.+flake8_type_annotations-0.1.0.dist-info/RECORDPK