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
9 changed files with 314 additions and 3 deletions

No files matched your search

+1
View File
@@ -10,6 +10,7 @@
### Changed ### Changed
- Replaced the installation instructions, which used the old registry, with a reference to the Gitea Package Registry in README - Replaced the installation instructions, which used the old registry, with a reference to the Gitea Package Registry in README
- Made Python function signatures (argument default values) compliant with PEP 8
### Deprecated ### Deprecated
@@ -142,6 +142,9 @@ class PythonFunctionArgument:
str_repr += ': ' + self.annotation str_repr += ': ' + self.annotation
if self.default is not None: if self.default is not None:
if self.annotation is None:
str_repr += '=' + self.default
else:
str_repr += ' = ' + self.default str_repr += ' = ' + self.default
return str_repr return str_repr
@@ -249,6 +249,46 @@ def _signature_section(signature: str) -> str:
'allow_html: bool = True, level: int = 1) -> None' '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( def test_PythonDefinitionDocumentationGenerator_generate_signature(
@@ -7,3 +7,33 @@
```python ```python
func() 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 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. 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` ## Function `add`
Adds two numbers. Adds two numbers.
@@ -422,6 +452,36 @@ A dog.""",
A test module. 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` ## Function `add`
Adds two numbers. Adds two numbers.
@@ -604,6 +664,35 @@ A dog.""",
A test module. 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` ## Function `add`
Adds two numbers. Adds two numbers.
@@ -782,6 +871,68 @@ Return type: `None`
A test module. 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` ## Function `add`
Adds two numbers. Adds two numbers.
@@ -1001,6 +1152,69 @@ Return type: `None`
A test module. 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` ## Function `add`
Adds two numbers. Adds two numbers.
@@ -341,6 +341,17 @@ from src.jcloud_docsgen.core.python.arguments import (
], ],
['a: int = 1'], ['a: int = 1'],
), ),
(
[
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
'1',
None,
),
],
['a=1'],
),
], ],
) )
def test__signature_argument_list(argument_list, expected): 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: def add(a: int | float, b: int | float) -> int | float:
""" """
Adds two numbers. Adds two numbers.
@@ -727,9 +727,7 @@ def argument_list(argument_list: str) -> ast.arguments:
], ],
), ),
( (
argument_list( argument_list("a, b='a', /, *args, c=None, d=True, **kwargs"),
"a, b = 'a', /, *args, c = None, d = True, **kwargs"
),
[ [
PythonFunctionArgument( PythonFunctionArgument(
'a', 'a',