|
7 | 7 | import libcst |
8 | 8 | from libcst.codemod import CodemodContext, VisitorBasedCodemodCommand |
9 | 9 | from libcst.codemod.visitors import AddImportsVisitor |
10 | | -from libcst.metadata import PositionProvider |
| 10 | +from libcst.metadata import CodePosition, CodeRange, PositionProvider |
| 11 | + |
| 12 | +_DEFAULT_POSITION = CodePosition(0, 0) |
| 13 | +_DEFAULT_CODE_RANGE = CodeRange(_DEFAULT_POSITION, _DEFAULT_POSITION) |
11 | 14 |
|
12 | 15 |
|
13 | 16 | @dataclass |
@@ -294,7 +297,9 @@ def leave_FunctionDef( |
294 | 297 | lineno_node = original_node.decorators[0] |
295 | 298 | else: |
296 | 299 | lineno_node = original_node |
297 | | - pos = self.get_metadata(PositionProvider, lineno_node).start |
| 300 | + pos = self.get_metadata( |
| 301 | + PositionProvider, lineno_node, _DEFAULT_CODE_RANGE |
| 302 | + ).start |
298 | 303 | key = (self.context.filename, pos.line, pos.column) |
299 | 304 | suggestion = self.state.pyanalyze_suggestions.get(key) |
300 | 305 | if suggestion is not None and not ( |
@@ -442,7 +447,9 @@ def leave_Param( |
442 | 447 | if original_node.annotation is not None: |
443 | 448 | return updated_node |
444 | 449 | if self.state.pyanalyze_suggestions and self.context.filename: |
445 | | - pos = self.get_metadata(PositionProvider, original_node).start |
| 450 | + pos = self.get_metadata( |
| 451 | + PositionProvider, original_node, _DEFAULT_CODE_RANGE |
| 452 | + ).start |
446 | 453 | key = (self.context.filename, pos.line, pos.column) |
447 | 454 | suggestion = self.state.pyanalyze_suggestions.get(key) |
448 | 455 | if suggestion is not None and not ( |
|
0 commit comments