Skip to content

Commit 4120bad

Browse files
Merge pull request #1 from FHPythonUtils/v3
V3
2 parents 26f346c + 8393d37 commit 4120bad

61 files changed

Lines changed: 1265 additions & 1640 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.pre-commit-config.yaml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: lint
5+
name: lint
6+
language: system
7+
pass_filenames: false
8+
entry: uvx ruff check --fix
9+
- id: format
10+
name: format
11+
language: system
12+
pass_filenames: false
13+
entry: uvx ruff format
14+
- id: vulture
15+
name: vulture
16+
language: system
17+
pass_filenames: false
18+
entry: uvx vulture
19+
- id: pyright
20+
name: pyright
21+
language: system
22+
pass_filenames: false
23+
entry: uv run pyright mypy_boto3_builder
24+
- id: mypy
25+
name: mypy
26+
language: system
27+
pass_filenames: false
28+
entry: uv run mypy mypy_boto3_builder
29+
- id: pytest
30+
name: pytest
31+
language: system
32+
pass_filenames: false
33+
entry: uv run pytest

‎handsdown/__init__.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Root of `handsdown` source code.
3-
"""
1+
"""Root of `handsdown` source code."""
42

53
name = "handsdown"
64
__all__ = ["name"]

‎handsdown/__main__.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Main module entrypoint.
3-
"""
1+
"""Main module entrypoint."""
42
from handsdown.main import main
53

64
if __name__ == "__main__":

‎handsdown/ast_parser/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
# AST Parser
2+
# AST Parser.
33
44
Collection of tools for analyzing AST and also rendering it back to a valid Python code.
55
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
"""
2-
AST Analyzers.
3-
"""
1+
"""AST Analyzers."""

‎handsdown/ast_parser/analyzers/base_analyzer.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
Base AST analyzer.
3-
"""
4-
from typing import List
1+
"""Base AST analyzer."""
52

63
import handsdown.ast_parser.smart_ast as ast
74

@@ -14,7 +11,7 @@ class BaseAnalyzer(ast.NodeVisitor):
1411
"""
1512

1613
def __init__(self) -> None:
17-
self.related_names: List[str] = []
14+
self.related_names: list[str] = []
1815

1916
def get_docstring(self, node: ast.AST) -> str:
2017
"""
@@ -25,6 +22,7 @@ def get_docstring(self, node: ast.AST) -> str:
2522
2623
Returns:
2724
Docstring.
25+
2826
"""
2927
if isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef, ast.Module)):
3028
return ast.get_docstring(node, clean=False) or ""

‎handsdown/ast_parser/analyzers/class_analyzer.py‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
"""
2-
AST analyzer for `ast.ClassDef` records.
3-
"""
4-
from typing import List, Union
1+
"""AST analyzer for `ast.ClassDef` records."""
2+
from typing import Union
53

64
import handsdown.ast_parser.smart_ast as ast
75
from handsdown.ast_parser.analyzers.base_analyzer import BaseAnalyzer
86
from handsdown.ast_parser.type_defs import ASTFunctionDef
97

108

119
class ClassAnalyzer(BaseAnalyzer):
12-
"""
13-
AST analyzer for `ast.ClassDef` records.
14-
"""
10+
"""AST analyzer for `ast.ClassDef` records."""
1511

1612
def __init__(self) -> None:
1713
super().__init__()
18-
self.base_nodes: List[ast.expr] = []
19-
self.decorator_nodes: List[ast.expr] = []
20-
self.method_nodes: List[ASTFunctionDef] = []
21-
self.attribute_nodes: List[Union[ast.Assign, ast.AnnAssign]] = []
14+
self.base_nodes: list[ast.expr] = []
15+
self.decorator_nodes: list[ast.expr] = []
16+
self.method_nodes: list[ASTFunctionDef] = []
17+
self.attribute_nodes: list[Union[ast.Assign, ast.AnnAssign]] = []
2218

2319
def visit_ClassDef(self, node: ast.ClassDef) -> None:
2420
"""
@@ -37,6 +33,7 @@ def my_func():
3733
3834
Arguments:
3935
node -- AST node.
36+
4037
"""
4138
for decorator_node in node.decorator_list:
4239
self.decorator_nodes.append(decorator_node)
@@ -51,14 +48,12 @@ def _visit_FunctionDef(self, node: ASTFunctionDef) -> None:
5148
docstring = self.get_docstring(node)
5249

5350
# skip private methods with no docstrings
54-
if name.startswith("_"):
55-
if not name.startswith("__") and not docstring:
56-
return
51+
if name.startswith("_") and not name.startswith("__") and not docstring:
52+
return
5753

5854
# skip magic methods with no docstrings
59-
if name.startswith("__"):
60-
if name != "__init__" and not docstring:
61-
return
55+
if name.startswith("__") and name != "__init__" and not docstring:
56+
return
6257

6358
self.method_nodes.append(node)
6459

@@ -77,6 +72,7 @@ def my_method(self, arg):
7772
7873
Arguments:
7974
node -- AST node.
75+
8076
"""
8177
self._visit_FunctionDef(node)
8278

@@ -95,6 +91,7 @@ async def my_method(self, arg):
9591
9692
Arguments:
9793
node -- AST node.
94+
9895
"""
9996
self._visit_FunctionDef(node)
10097

@@ -121,6 +118,7 @@ class MyClass:
121118
122119
Arguments:
123120
node -- AST node.
121+
124122
"""
125123
# skip multiple assignments
126124
if len(node.targets) != 1:
@@ -154,6 +152,7 @@ class MyClass:
154152
155153
Arguments:
156154
node -- AST node.
155+
157156
"""
158157
# skip complex assignments
159158
if not isinstance(node.target, ast.Name):
@@ -173,4 +172,5 @@ def generic_visit(self, node: ast.AST) -> None:
173172
174173
Arguments:
175174
node -- AST node.
175+
176176
"""

0 commit comments

Comments
 (0)