Skip to content

Commit

Permalink
Typing changes for 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Sep 14, 2023
1 parent 84b2ed7 commit aaf31c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/codemodder/codemods/https_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def match_line(pos, line):
return pos.start.line == line and pos.end.line == line


def count_positional_args(arglist: Sequence[cst.Arg]) -> int | None:
def count_positional_args(arglist: Sequence[cst.Arg]) -> int:
for i, arg in enumerate(arglist):
if arg.keyword:
return i
Expand Down
13 changes: 8 additions & 5 deletions src/codemodder/codemods/utils_mixin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional, Union
import libcst as cst
from libcst import MetadataDependent, matchers
from libcst.helpers import get_full_name_for_node
Expand Down Expand Up @@ -42,7 +43,7 @@ def base_name_for_import(self, import_node, import_alias):

def _is_direct_call_from_imported_module(
self, call: cst.Call
) -> tuple[cst.Import | cst.ImportFrom, cst.ImportAlias] | None:
) -> Optional[tuple[Union[cst.Import, cst.ImportFrom], cst.ImportAlias]]:
for nodo in iterate_left_expressions(call):
if matchers.matches(nodo, matchers.Name() | matchers.Attribute()):
maybe_assignment = self.find_single_assignment(nodo)
Expand All @@ -57,7 +58,8 @@ def _is_direct_call_from_imported_module(
return None

def find_assignments(
self, node: cst.Name | cst.Attribute | cst.Call | cst.Subscript | cst.Decorator
self,
node: Union[cst.Name, cst.Attribute, cst.Call, cst.Subscript, cst.Decorator],
) -> set[Assignment]:
"""
Given a MetadataWrapper and a CSTNode with a possible access to it, find all the possible assignments that it refers.
Expand All @@ -76,8 +78,9 @@ def find_assignments(
return set()

def find_single_assignment(
self, node: cst.Name | cst.Attribute | cst.Call | cst.Subscript | cst.Decorator
) -> Assignment | None:
self,
node: Union[cst.Name, cst.Attribute, cst.Call, cst.Subscript, cst.Decorator],
) -> Optional[Assignment]:
"""
Given a MetadataWrapper and a CSTNode representing an access, find if there is a single assignment that it refers to.
"""
Expand Down Expand Up @@ -106,7 +109,7 @@ def get_leftmost_expression(node: cst.BaseExpression) -> cst.BaseExpression:
return node


def _get_name(node: cst.Import | cst.ImportFrom) -> str:
def _get_name(node: Union[cst.Import, cst.ImportFrom]) -> str:
"""
Get the full name of a module referenced by a Import or ImportFrom node.
For relative modules, dots are added at the beginning
Expand Down

0 comments on commit aaf31c5

Please sign in to comment.