2 Commits
Author SHA1 Message Date
jakob.scheid 045167098f docs(changelog): add Python signatures PEP 8 compliance entry
Added a changelog entry for the PEP 8 compliance of Python function
signatures default values.
2026-09-22 16:09:30 +02:00
jakob.scheid 31995e830b test(python-generator): update tests to PEP 8 compliance
Updated test cases to the new default value PEP 8 compliance and added
new test cases to test the new behavior.
2026-09-22 16:04:20 +02:00
9 changed files with 328 additions and 21 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
@@ -131,7 +131,7 @@ def _signature_section(signature: str) -> str:
[], [],
), ),
), ),
"a(a = '42') -> str", "a(a='42') -> str",
), ),
( (
PythonDefinitionDocumentationGenerator( PythonDefinitionDocumentationGenerator(
@@ -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(
@@ -371,7 +411,7 @@ def test_PythonDefinitionDocumentationGenerator_generate_signature_exceptions(
[], [],
), ),
), ),
"a(a = '42') -> str", "a(a='42') -> str",
), ),
( (
PythonDefinitionDocumentationGenerator( PythonDefinitionDocumentationGenerator(
@@ -1796,7 +1836,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -1938,7 +1978,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -2081,7 +2121,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -2191,7 +2231,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -2301,7 +2341,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -2446,7 +2486,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -2592,7 +2632,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -2705,7 +2745,7 @@ Very long ...
## Function signature ## Function signature
```python ```python
a(hello: int, /, world = 1, *, something: str = 'something', **value) -> bool a(hello: int, /, world=1, *, something: str = 'something', **value) -> bool
``` ```
## Returns ## Returns
@@ -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,7 @@
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):
@@ -2,6 +2,11 @@
A test module. 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:
""" """
@@ -685,7 +685,7 @@ def argument_list(argument_list: str) -> ast.arguments:
), ),
( (
argument_list( argument_list(
"a = 1, b = 'a', /, *args, c = None, d = True, **kwargs", "a=1, b='a', /, *args, c=None, d=True, **kwargs",
), ),
[ [
PythonFunctionArgument( PythonFunctionArgument(
@@ -728,7 +728,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(
@@ -767,7 +767,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( PythonFunctionArgument(
'a', 'a',
@@ -808,7 +808,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( PythonFunctionArgument(
'a', 'a',
@@ -890,7 +890,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( PythonFunctionArgument(
'a', 'a',
@@ -931,7 +931,7 @@ def argument_list(argument_list: str) -> ast.arguments:
], ],
), ),
( (
argument_list('a = 1'), argument_list('a=1'),
[ [
PythonFunctionArgument( PythonFunctionArgument(
'a', 'a',
@@ -362,7 +362,7 @@ from src.jcloud_docsgen.exceptions import (
'1', '1',
None, None,
PythonArgumentStructureError, PythonArgumentStructureError,
'* or ** arguments cannot have default values: *a = 1', '* or ** arguments cannot have default values: *a=1',
), ),
( (
'a', 'a',
@@ -370,7 +370,7 @@ from src.jcloud_docsgen.exceptions import (
'1', '1',
None, None,
PythonArgumentStructureError, 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', '1',
None, None,
), ),
'a = 1', 'a=1',
), ),
( (
PythonFunctionArgument( PythonFunctionArgument(
@@ -531,7 +531,7 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
'1', '1',
None, None,
), ),
'a = 1', 'a=1',
), ),
( (
PythonFunctionArgument( PythonFunctionArgument(
@@ -567,7 +567,7 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
'1', '1',
None, None,
), ),
'a = 1', 'a=1',
), ),
( (
PythonFunctionArgument( PythonFunctionArgument(