xennygrimmato / py-data-dependency-graph

Data dependency graph for Python programs
3 stars 0 forks source link

Sweep: Add type hints for all py files #11

Open xennygrimmato opened 6 months ago

xennygrimmato commented 6 months ago

Details

Add typehints to all the code that is used by main.py (e.g. code_to_data_dependency_graph, var_ddg)

Checklist - [X] Modify `code_to_data_dependency_graph.py` ✓ https://github.com/xennygrimmato/py-data-dependency-graph/commit/c79c4790e6bdf5ae1efca4ed5de54d41692a81de [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/code_to_data_dependency_graph.py#L4-L47) - [X] Running GitHub Actions for `code_to_data_dependency_graph.py` ✓ [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/code_to_data_dependency_graph.py#L4-L47) - [X] Modify `code_to_data_dependency_graph.py` ✓ https://github.com/xennygrimmato/py-data-dependency-graph/commit/3c12f4211dc71f32a005254b8df188056f7f705a [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/code_to_data_dependency_graph.py#L49-L90) - [X] Running GitHub Actions for `code_to_data_dependency_graph.py` ✓ [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/code_to_data_dependency_graph.py#L49-L90) - [X] Modify `code_to_data_dependency_graph.py` ✓ https://github.com/xennygrimmato/py-data-dependency-graph/commit/1b4a5b7ff4b45c1a80766af51462d814db67e445 [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/code_to_data_dependency_graph.py#L93-L96) - [X] Running GitHub Actions for `code_to_data_dependency_graph.py` ✓ [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/code_to_data_dependency_graph.py#L93-L96) - [X] Modify `var_ddg.py` ✓ https://github.com/xennygrimmato/py-data-dependency-graph/commit/c610f1763e9196c198d8c38041e72c25897d0136 [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/var_ddg.py#L4-L73) - [X] Running GitHub Actions for `var_ddg.py` ✓ [Edit](https://github.com/xennygrimmato/py-data-dependency-graph/edit/sweep/add_type_hints_for_all_py_files/var_ddg.py#L4-L73)
sweep-ai[bot] commented 6 months ago

🚀 Here's the PR! #12

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: ff4cc2a4a4)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

[!TIP] I'll email you at vstulsyan@gmail.com when I complete this pull request!


Actions (click)

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for fd8af0e
Checking code_to_data_dependency_graph.py for syntax errors... ✅ code_to_data_dependency_graph.py has no syntax errors! 1/1 ✓
Checking code_to_data_dependency_graph.py for syntax errors...
✅ code_to_data_dependency_graph.py has no syntax errors!

Sandbox passed on the latest master, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/xennygrimmato/py-data-dependency-graph/blob/fd8af0e114becf1250b70d6ef16c4b94ae1a2e31/main.py#L1-L37 https://github.com/xennygrimmato/py-data-dependency-graph/blob/fd8af0e114becf1250b70d6ef16c4b94ae1a2e31/code_to_data_dependency_graph.py#L3-L96 https://github.com/xennygrimmato/py-data-dependency-graph/blob/fd8af0e114becf1250b70d6ef16c4b94ae1a2e31/var_ddg.py#L3-L73

Step 2: ⌨️ Coding

--- 
+++ 
@@ -1,13 +1,13 @@
 import ast

-def get_deps(code):
+def get_deps(code: str) -> Tuple[Dict[str, int], Dict[str, Set[str]]]:
     body = ast.parse(code)
     _, statements = next(ast.iter_fields(body))

     # Line no. at which each identifier was first seen
-    declaration_line_num_map = {}
-    ddg = {}
+    declaration_line_num_map: Dict[str, int] = {}
+    ddg: Dict[str, Set[str]] = {}

     def update_decls(lhs_vars_input, num):
         lhs_var_nodes = []

Ran GitHub Actions for c79c4790e6bdf5ae1efca4ed5de54d41692a81de:

--- 
+++ 
@@ -1,13 +1,13 @@
 import ast

-def get_deps(code):
+def get_deps(code: str) -> Tuple[Dict[str, int], Dict[str, Set[str]]]:
     body = ast.parse(code)
     _, statements = next(ast.iter_fields(body))

     # Line no. at which each identifier was first seen
-    declaration_line_num_map = {}
-    ddg = {}
+    declaration_line_num_map: Dict[str, int] = {}
+    ddg: Dict[str, Set[str]] = {}

     def update_decls(lhs_vars_input, num):
         lhs_var_nodes = []
@@ -51,7 +51,7 @@
     def __init__(self, code):
         self.parsed_ast = ast.parse(code)

-    def get_methods(self):
+    def get_methods(self) -> List[ast.FunctionDef]:
         fn_nodes = []

         class FnVisitor(ast.NodeVisitor):

Ran GitHub Actions for 3c12f4211dc71f32a005254b8df188056f7f705a:

--- 
+++ 
@@ -1,13 +1,13 @@
 import ast

-def get_deps(code):
+def get_deps(code: str) -> Tuple[Dict[str, int], Dict[str, Set[str]]]:
     body = ast.parse(code)
     _, statements = next(ast.iter_fields(body))

     # Line no. at which each identifier was first seen
-    declaration_line_num_map = {}
-    ddg = {}
+    declaration_line_num_map: Dict[str, int] = {}
+    ddg: Dict[str, Set[str]] = {}

     def update_decls(lhs_vars_input, num):
         lhs_var_nodes = []
@@ -51,7 +51,7 @@
     def __init__(self, code):
         self.parsed_ast = ast.parse(code)

-    def get_methods(self):
+    def get_methods(self) -> List[ast.FunctionDef]:
         fn_nodes = []

         class FnVisitor(ast.NodeVisitor):
@@ -90,7 +90,7 @@
         return ddg

-def fn_ddgs(code):
+def fn_ddgs(code: str) -> Dict[str, Dict[str, Set[str]]]:
     method_level_ddgs = MethodLevelDDGs(code)
     methods = method_level_ddgs.get_methods()
     ddgs = {method.name: method_level_ddgs.recursive_ddg(method) for method in methods}

Ran GitHub Actions for 1b4a5b7ff4b45c1a80766af51462d814db67e445:

--- 
+++ 
@@ -2,7 +2,7 @@

 class MyVisitor:
-    def __init__(self, path):
+    def __init__(self, path: str):
         self.GLOBAL_FN = ast.FunctionDef(name='_global_')

         # FunctionDef -> set(x, y) such that x reads y
@@ -67,8 +67,10 @@
         if is_fn:
             self.fn_stack.pop()

-    def construct_ddg(self):
+    def construct_ddg(self) -> None:
         self.ast_visit(self.tree)

     def get_function_level_ddg(self):
         return {fn.name: value for fn, value in self.fn_to_ddg_map.items()}
+    def get_function_level_ddg(self) -> Dict[ast.FunctionDef, Set[Tuple[str, str]]]:
+        return {fn.name: value for fn, value in self.fn_to_ddg_map.items()}

Ran GitHub Actions for c610f1763e9196c198d8c38041e72c25897d0136:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/add_type_hints_for_all_py_files.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.