Package: type-hint-checker
Type hint checkerChecks that the parameters in functions and methods have type hints.Type hint checkeris intended to be used as apre-commithook.deff1(a):pass>gitcommittype_hint_checker.......................................................Failed-hookid:type_hint_checker-duration:0.33s-exitcode:1INFO:type_hint_checker:test.py:Missingtypehintforparametera(functionf1),line1INFO:type_hint_checker:test.py:Missingreturntypehintforfunctionf1,line1Quick startInstall pre-commit hookshttps://pre-commit.com/#installpipinstallpre-commitCreate a.pre-commit-config.yamlor use your existing config file. Add the following lines:repos:-repo:https://github.com/PaulinaPacyna/type-hint-checkerrev:latesthooks:-id:type_hint_checkername:type_hint_checkerdescription:Check that all python functions have type hintsentry:type_hint_checkerlanguage:pythonverbose:truefiles:".py$"args:[#--exit_zero, # always exit with 0 code#--exclude_files=tests, #exclude all paths that have the string tests inside#--exclude_parameters=^self$, #don't throw warnings about self parameter]Install the pre-commit hookpre-commit installCommit a fileecho'def f1(a): pass'>test.pygitcommittest.py-m"Test type_hint_checker pre-commit hook"The output should be similar to this:type_hint_checker.......................................................Failed
 - hook id: type_hint_checker
 - duration: 0.33s
 - exit code: 1
 
 INFO:type_hint_checker:test.py: Missing type hint for parameter a (function f1), line 1
 INFO:type_hint_checker:test.py: Missing return type hint for function f1, line 1Run type hint checker from terminalIf you already have it installed in pre-commit hooks:pre-commit run type_hint_checker --all-filesTry the cli version out by runningpipinstalltype_hint_checkerRun the tool usingtype_hint_checker<pathtofile>orpython-mtype_hint_checker<pathtofile>ArgumentsIt is understandable that there are different coding standards. You can customize the behavior of this pre-commit hook by adding the following options to your.pre-commit-config.yaml.ArgumentUsageDefault valueExample values--exit_zeroIf this flag is checked, the program always exits with 0 (success) code. It is strongly advised to use this flag together withverbose: trueoption in pre-commit options.Not checked by default.Either add"--exit_zero"to theargsor don't.--exclude_filesRegex specifying which files should not be checked.Empty (all files are checked)"--exclude_files=^test_"--exclude_parametersRegex specifying which parameters should not be checked.^self$"--exclude_parameters=''"(check all params)"--exclude_parameters='(^self$|logger)'"--exclude_by_nameRegex specifying names of functions, methods and classes that should not be checkedEmpty (all functions, classes and methods are checked)."--exclude_by_name='^test_'"--log-levelIf set toDEBUG, displays more logs.INFO"--log-level=INFO","--log-level=DEBUG"--ignore_commentYou can change the content of the comment that disables checking a given function or method. By default#no-checkexcludes the item from being checked. See below for more info.no-check"--ignore_comment='hint-no-check'"If you have troubles setting those values, it may be due to how your system parses special characters in command line options. Add--log-level=DEBUGto you.pre-commit-config.yaml. The log message will show you what values are passed as command line arguments.DEBUG:type_hint_checker:{'filenames': ['test.py'],
 'exit_zero': False, 
'exclude_files': 'tests/', 
'exclude_parameters': '^self$', 
'exclude_by_name': '', 
'log_level': 'DEBUG', 
'ignore_comment': 'no-check'}Disable warningsIf you find type_hint_checker too restrictive, you are welcome to adjust its behavior. You can choose to ignore whole files, functions, parameters or single linesIgnore a pathIf you don't want to check a certain file or folder, add the path to the--exclude_filesargument. The argument must be a valid regex. To omit checking the directorytests/and the filesetup.pyuse the following regex in your.pre-commit-config:args:["--exclude_files='(tests/|setup.py)'"]Ignore a function by nameYou can disable checking functions that are named in a certain way. To disable checking all functions that begin withtest_prefix, use:args:["--exclude_by_name='^test_"]Then, for example this signature won't throw a warning:deftest_filepath_in_log(caplog):...Ignore a parameter by nameYou can disable checking parameters with a regex, e.g. theselfparameterargs:[--exclude_parameters=^self$]With the option shown above, this method signature won't throw any warnings:classFileMaker:defread_file(self)->str:...With a commentIn special cases, you can just put#no-checkcomment next to the function, and the function will be omitted by this pre-commit hook.deffunc(a:int,b:int,n):#no-checkpassThe pre-commit hook will not warn you about the missing type hint for the return and parametern.
You can customize the comment content using--ignore_commentoption.In case of fireYou can always commit without any pre-commit checks usinggitcommit--no-verifyPep8 specification about type hintsThe default formatting options were set in accordance toPEP8 484TestsTo run the tests, runpython-mpytesttests/