Package: pyleft
PyLeftPython type annotation existence checkerpyleftis a complement to Microsoft'spyrighttool. Whilepyrightdoes an excellent job at type checking your Python code,
it doesn't check to make sure type hints exist. If you forget to add type hints
to a function,pyrightwill usually see no problems with it. This tool checks
to make sure all of your codehastype hints, while leaving it topyrightto make sure they are actually correct.InstallationPyLeft requires Python 3.7+.pip install pyleftUsagePyLeft is a Python module that can be run viapython -m. Just provide the directories
or files to recursively check.pyleft .The module will exit with an exit code of 0 if all type hints are present, or 1
if there are any issues.Example>pyleft."C:\Users\nvaug\Repos\pyleft\tests\files\fail_4.py:4"Argument'one'offunction'wheels'hasnotypeannotation"C:\Users\nvaug\Repos\pyleft\tests\files\fail_1.py:1"Argument'two'offunction'add'hasnotypeannotation"C:\Users\nvaug\Repos\pyleft\tests\files\fail_3.py:2"Function'drive'hasnoreturntypeannotation"C:\Users\nvaug\Repos\pyleft\tests\files\options_1.py:1"Argument'arg1'offunction'positional_default_value'hasnotypeannotation"C:\Users\nvaug\Repos\pyleft\tests\files\options_1.py:5"Argument'arg2'offunction'keyword_default_value'hasnotypeannotation"C:\Users\nvaug\Repos\pyleft\tests\files\fail_2.py:1"Function'add'hasnoreturntypeannotationPre-CommitThis can also be used as apre-commithook:-hooks:-id:pyleftrepo:https://github.com/nathanvaughn/pyleftrev:v1.2.1Optionspaths: File and directory names to recursively check.--exclude: (optional) List of pattern(s) of files/directories to exclude in
gitignore format. Takes precedence overpaths.--no-gitignore: (optional) Don't use the exclusions from the .gitignore file(s)
in the current working directory.--ignore-if-has-default: (optional) Ignore a lack of annotation if a function
argument has a default value.--quiet: (optional) Don't print any output to STDOUT.--verbose: (optional) Print debugging information to STDERR.ConfigurationConfiguration is done through thepyproject.tomlfile.[tool.pyleft]# "paths" in the configuration file are added to the option given on the# command line# This can either be a list, or a space separated stringpaths=["extra/directory/"]# This can either be a list, or a space separated stringexclude=["*_pb2.py"]# These are all booleansno-gitignore=falseignore-if-has-default=falsequiet=falseverbose=falseDesign DecisionsIf a.pyifile exists alongside a.pyfile, only the.pyifile will be checked.The__init__and__new__methods of a class are not required to
have return type hints.pyrightautomatically assumes this to beNone.The first (self) argument of any class method is not required to have a type hint.The first (cls) argument of any class@propertyor@classmethodor__new__method is not required to have a type hint.Any variable argument list (*arg) or keyword argument dict (**kwarg)
is not required to have a type hint.Types of types, such asListorTupleare not required. For example,
a type hint of justlistis allowed, although you should normally be as specific
as possible with a better type hint likeList[int].Individual functions can be ignored with a# noqacomment on the same line.DisclaimerThis project is not affiliated in any way with Microsoft.