LibCST/libcst/codemod
Steven Troxler 595d8c3948
Add support for methods with func type comment excluding self/cls (#622)
* Add support for methods with func type comment excluding self/cls

PEP 484 doesn't really specify carefully how function type
comments should work on methods, but since usually the type of
`self` / `cls` is automatic, most use cases choose to only annotate
the other arguments.

As a result, this commit modifies our codemod so that non-static
methods can specify either all the arguments, or all but one of
them. We'll correctly zip together the inline and func-type-comment
types either way, typically getting no type for `cls` or `self`.

We accomplish this by using matchers to trigger the visit
method for FunctionDef rather than using visit_FunctionDef, which gives
us enough context to determine when a function def is a regular
function versus a method (plus also matching the decorators against
`@staticmethod`, so that we trigger the normal function logic in
that case).

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2022-01-25 09:37:36 -08:00
..
commands Add support for methods with func type comment excluding self/cls (#622) 2022-01-25 09:37:36 -08:00
tests Fix license headers (#560) 2021-12-28 11:55:18 +00:00
visitors Merge in TypeVars and Generic base classes in ApplyTypeAnnotationVisitor (#596) 2022-01-14 11:39:18 -08:00
__init__.py Fix license headers (#560) 2021-12-28 11:55:18 +00:00
_cli.py Fix all type errors (#579) 2022-01-05 18:13:01 +00:00
_codemod.py Fix license headers (#560) 2021-12-28 11:55:18 +00:00
_command.py Fix all type errors (#579) 2022-01-05 18:13:01 +00:00
_context.py Fix license headers (#560) 2021-12-28 11:55:18 +00:00
_dummy_pool.py Fix license headers (#560) 2021-12-28 11:55:18 +00:00
_runner.py Fix license headers (#560) 2021-12-28 11:55:18 +00:00
_testing.py Fix all type errors (#579) 2022-01-05 18:13:01 +00:00
_visitor.py Fix license headers (#560) 2021-12-28 11:55:18 +00:00