Merge pull request 'Fix(python-generator): make generated signatures compliant with PEP 8' (#35) from fix/python-signatures-pep-8-compliance into main

Reviewed-on: #35
This commit was merged in pull request #35.
This commit is contained in:
jakob.scheid authored and Gitea committed 2026-09-22 16:15:35 +02:00
commit 63cef6f641
10 files changed
+336 -25

No files matched your search

+1
View File
@@ -10,6 +10,7 @@
### Changed
- 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
+4 -1
View File
@@ -142,7 +142,10 @@ class PythonFunctionArgument:
str_repr += ': ' + self.annotation
if self.default is not None:
str_repr += ' = ' + self.default
if self.annotation is None:
str_repr += '=' + self.default
else:
str_repr += ' = ' + self.default
return str_repr
@@ -131,7 +131,7 @@ def _signature_section(signature: str) -> str:
[],
),
),
"a(a = '42') -> str",
"a(a='42') -> str",
),
(
PythonDefinitionDocumentationGenerator(
@@ -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(
@@ -371,7 +411,7 @@ def test_PythonDefinitionDocumentationGenerator_generate_signature_exceptions(
[],
),
),
"a(a = '42') -> str",
"a(a='42') -> str",
),
(
PythonDefinitionDocumentationGenerator(
@@ -1796,7 +1836,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -1938,7 +1978,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -2081,7 +2121,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -2191,7 +2231,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -2301,7 +2341,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -2446,7 +2486,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -2592,7 +2632,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -2705,7 +2745,7 @@ Very long ...
## Function signature
```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool
a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
```
## Returns
@@ -6,4 +6,34 @@
```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.
@@ -685,7 +685,7 @@ def argument_list(argument_list: str) -> ast.arguments:
),
(
argument_list(
"a = 1, b = 'a', /, *args, c = None, d = True, **kwargs",
"a=1, b='a', /, *args, c=None, d=True, **kwargs",
),
[
PythonFunctionArgument(
@@ -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',
@@ -767,7 +765,7 @@ def argument_list(argument_list: str) -> ast.arguments:
],
),
(
argument_list('a, b , /, *args, c = None, d = True, **kwargs'),
argument_list('a, b , /, *args, c=None, d=True, **kwargs'),
[
PythonFunctionArgument(
'a',
@@ -808,7 +806,7 @@ def argument_list(argument_list: str) -> ast.arguments:
],
),
(
argument_list('a, b , /, *args, c, d = True, **kwargs'),
argument_list('a, b , /, *args, c, d=True, **kwargs'),
[
PythonFunctionArgument(
'a',
@@ -890,7 +888,7 @@ def argument_list(argument_list: str) -> ast.arguments:
],
),
(
argument_list('a, b , /, *args, c = None, d, **kwargs'),
argument_list('a, b , /, *args, c=None, d, **kwargs'),
[
PythonFunctionArgument(
'a',
@@ -931,7 +929,7 @@ def argument_list(argument_list: str) -> ast.arguments:
],
),
(
argument_list('a = 1'),
argument_list('a=1'),
[
PythonFunctionArgument(
'a',
@@ -362,7 +362,7 @@ from src.jcloud_docsgen.exceptions import (
'1',
None,
PythonArgumentStructureError,
'* or ** arguments cannot have default values: *a = 1',
'* or ** arguments cannot have default values: *a=1',
),
(
'a',
@@ -370,7 +370,7 @@ from src.jcloud_docsgen.exceptions import (
'1',
None,
PythonArgumentStructureError,
'* or ** arguments cannot have default values: **a = 1',
'* or ** arguments cannot have default values: **a=1',
),
],
)
@@ -498,7 +498,7 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
'1',
None,
),
'a = 1',
'a=1',
),
(
PythonFunctionArgument(
@@ -531,7 +531,7 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
'1',
None,
),
'a = 1',
'a=1',
),
(
PythonFunctionArgument(
@@ -567,7 +567,7 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
'1',
None,
),
'a = 1',
'a=1',
),
(
PythonFunctionArgument(