Skip to content

Commit

Permalink
Apply annotations from stub.
Browse files Browse the repository at this point in the history
Basically move the apply_annotations code from Pyre.

Make it a ContextAwareTransformer named ApplyTypeAnnotationsVisitor. Use GatherImportsVisitor to collect imports. Add a static method `add_stub_to_context` so that users can schedule a stub whose types are to be applied later. Use `assertCodemod` and `data_provider` in the tests. Add documentation. Remove fixmes.
  • Loading branch information
pradeep90 committed Mar 23, 2020
1 parent ea8619a commit b8c49ef
Show file tree
Hide file tree
Showing 4 changed files with 1,094 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/codemods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,5 @@ inside codemods. As of now, the list includes the following helpers.
:exclude-members: CONTEXT_KEY, visit_Module, leave_ImportFrom, leave_Module
.. autoclass:: libcst.codemod.visitors.RemoveImportsVisitor
:exclude-members: CONTEXT_KEY, METADATA_DEPENDENCIES, visit_Module, leave_ImportFrom, leave_Import
.. autoclass:: libcst.codemod.visitors.ApplyTypeAnnotationsVisitor
:exclude-members: CONTEXT_KEY, transform_module_impl, visit_ClassDef, visit_Comment, visit_FunctionDef, leave_Assign, leave_ClassDef, leave_FunctionDef, leave_ImportFrom, leave_Module
2 changes: 2 additions & 0 deletions libcst/codemod/visitors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# pyre-strict
from libcst.codemod.visitors._add_imports import AddImportsVisitor
from libcst.codemod.visitors._apply_type_annotations import ApplyTypeAnnotationsVisitor
from libcst.codemod.visitors._gather_exports import GatherExportsVisitor
from libcst.codemod.visitors._gather_imports import GatherImportsVisitor
from libcst.codemod.visitors._remove_imports import RemoveImportsVisitor
Expand All @@ -14,5 +15,6 @@
"AddImportsVisitor",
"GatherImportsVisitor",
"GatherExportsVisitor",
"ApplyTypeAnnotationsVisitor",
"RemoveImportsVisitor",
]
Loading

0 comments on commit b8c49ef

Please sign in to comment.