Fix(python-generator): make generated signatures compliant with PEP 8 #35

Merged
jakob.scheid merged 3 commits from fix/python-signatures-pep-8-compliance into main 2026-09-22 16:15:36 +02:00
7 changed files with 310 additions and 3 deletions
Showing only changes of commit 17c5e4938f - Show all commits

No files matched your search

@@ -249,6 +249,46 @@ def _signature_section(signature: str) -> str:
'allow_html: bool = True, level: int = 1) -> None'
),
),
(
PythonDefinitionDocumentationGenerator(
PythonFunctionDefinition(
'__init__',
[
PythonFunctionArgument(
'self',
PythonArgumentKind.NORMAL,
None,
None,
),
PythonFunctionArgument(
'definition',
PythonArgumentKind.NORMAL,
None,
'PythonDefinition',
),
PythonFunctionArgument(
'allow_html',
PythonArgumentKind.KEYWORD_ONLY,
'True',
'bool',
),
PythonFunctionArgument(
'level',
PythonArgumentKind.KEYWORD_ONLY,
'1',
None,
),
],
'None',
None,
[],
),
),
(
'__init__(self, definition: PythonDefinition, *, '
'allow_html: bool = True, level=1) -> None'
),
),
],
)
def test_PythonDefinitionDocumentationGenerator_generate_signature(
@@ -7,3 +7,33 @@
```python
func()
```
## Function `func2`
### Function signature
```python
func2(a: int, b: int = 42, c=42, d=42)
```
### Parameters
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `a` | `int` | normal | -- | -- |
| `b` | `int` | normal | `42` | -- |
| `c` | `int` | normal | `42` | -- |
| `d` | -- | normal | `42` | -- |
### Docstring
:param c:
:type c: int
@@ -1 +1,8 @@
def func(): ...
def func2(a: int, b: int = 42, c=42, d=42):
"""
:param c:
:type c: int
"""
@@ -241,6 +241,36 @@ def test_PythonModuleDocumentationGenerator_exceptions(
A test module.
## Function `fn`
### Function signature
```python
fn(a: int, b: int = 42, c=42, d=42)
```
### Parameters
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `a` | `int` | normal | -- | -- |
| `b` | `int` | normal | `42` | -- |
| `c` | `int` | normal | `42` | -- |
| `d` | -- | normal | `42` | -- |
### Docstring
:param c:
:type c: int
## Function `add`
Adds two numbers.
@@ -422,6 +452,36 @@ A dog.""",
A test module.
## Function `fn`
### Function signature
```python
fn(a: int, b: int = 42, c=42, d=42)
```
### Parameters
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `a` | `int` | normal | -- | -- |
| `b` | `int` | normal | `42` | -- |
| `c` | `int` | normal | `42` | -- |
| `d` | -- | normal | `42` | -- |
### Docstring
:param c:
:type c: int
## Function `add`
Adds two numbers.
@@ -604,6 +664,35 @@ A dog.""",
A test module.
## Function `fn`
### Function signature
```python
fn(a: int, b: int = 42, c=42, d=42)
```
### Parameters
| Parameter | Type | Kind | Default value | Description |
| --- | --- | --- | --- | --- |
| `a` | `int` | normal | -- | -- |
| `b` | `int` | normal | `42` | -- |
| `c` | `int` | normal | `42` | -- |
| `d` | -- | normal | `42` | -- |
<details><summary><h3 style="display:inline">Docstring</h3></summary>"""
""":param c:
:type c: int</details>
## Function `add`
Adds two numbers.
@@ -782,6 +871,68 @@ Return type: `None`
A test module.
## Function `fn`
### Function signature
```python
fn(a: int, b: int = 42, c=42, d=42)
```
### Parameters
- Parameter: `a`
Type: `int`
Kind: normal
Default value: --
Description: --
- Parameter: `b`
Type: `int`
Kind: normal
Default value: `42`
Description: --
- Parameter: `c`
Type: `int`
Kind: normal
Default value: `42`
Description: --
- Parameter: `d`
Type: --
Kind: normal
Default value: `42`
Description: --
<details><summary><h3 style="display:inline">Docstring</h3></summary>"""
""":param c:
:type c: int</details>
## Function `add`
Adds two numbers.
@@ -1001,6 +1152,69 @@ Return type: `None`
A test module.
## Function `fn`
### Function signature
```python
fn(a: int, b: int = 42, c=42, d=42)
```
### Parameters
- Parameter: `a`
Type: `int`
Kind: normal
Default value: --
Description: --
- Parameter: `b`
Type: `int`
Kind: normal
Default value: `42`
Description: --
- Parameter: `c`
Type: `int`
Kind: normal
Default value: `42`
Description: --
- Parameter: `d`
Type: --
Kind: normal
Default value: `42`
Description: --
### Docstring
:param c:
:type c: int
## Function `add`
Adds two numbers.
@@ -341,6 +341,17 @@ from src.jcloud_docsgen.core.python.arguments import (
],
['a: int = 1'],
),
(
[
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
'1',
None,
),
],
['a=1'],
),
],
)
def test__signature_argument_list(argument_list, expected):
@@ -3,6 +3,13 @@ A test module.
"""
def fn(a: int, b: int = 42, c=42, d=42):
"""
:param c:
:type c: int
"""
def add(a: int | float, b: int | float) -> int | float:
"""
Adds two numbers.
@@ -727,9 +727,7 @@ def argument_list(argument_list: str) -> ast.arguments:
],
),
(
argument_list(
"a, b = 'a', /, *args, c = None, d = True, **kwargs"
),
argument_list("a, b='a', /, *args, c=None, d=True, **kwargs"),
[
PythonFunctionArgument(
'a',