Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ceaea9c

Browse files
committed
regenerate stubs, amend according to flake8-pyi, ensure stub generation test is running in the CI
Signed-off-by: oleg.hoefling <[email protected]>
1 parent b04a762 commit ceaea9c

File tree

9 files changed

+188
-209
lines changed

9 files changed

+188
-209
lines changed

.appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ build_script:
4444
test: off
4545
test_script:
4646
- pip install -r requirements-test.txt
47+
- pip install black # for stub generation tests
4748
- pip install xmlsec --only-binary=xmlsec --no-index --find-links=dist
4849
- pytest -v --color=yes --junitxml=unittests.xml
4950
- ps: Get-ChildItem dist\*.whl | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

.github/workflows/sdist.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
PYXMLSEC_STATIC_DEPS: true
2121
run: |
2222
pip install --upgrade -r requirements-test.txt
23+
pip install black # for stub generation tests
2324
pip install dist/xmlsec-$(python setup.py --version).tar.gz
2425
- name: Run tests
2526
run: |

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.black]
22
line_length = 130
33
skip-string-normalization = true
4-
target_version = ['py38']
4+
target_version = ['py39']
55
include = '\.pyi?$'
66
exclude = '''
77

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ all_files = 1
1616
upload_dir = doc/build/html
1717

1818
[flake8]
19+
per-file-ignores =
20+
*.pyi: E301, E302, E305, E501, E701, F401, F822
21+
exclude = .venv*,.git,*_pb2.pyi,build,dist,libs,.eggs,.direnv*
1922
max-line-length = 130

src/xmlsec/__init__.pyi

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
1-
import sys
2-
from typing import (
3-
Any, AnyStr, Callable, IO, Iterable, Optional, Type, TypeVar, Union,
4-
overload)
1+
from collections.abc import Callable, Iterable
2+
from typing import Any, AnyStr, IO, typeVar, overload
3+
from _typeshed import GenericPath, Self, StrOrBytesPath
54

65
from lxml.etree import _Element
76

8-
from xmlsec import constants, template, tree
97
from xmlsec.constants import __KeyData as KeyData, __Transform as Transform
108

11-
if sys.version_info >= (3, 6):
12-
from os import PathLike
13-
from pathlib import PurePath
14-
15-
_Path = Union[str, bytes, PurePath, PathLike[str], PathLike[bytes]]
16-
elif sys.version_info >= (3, 4):
17-
from pathlib import PurePath
18-
19-
_Path = Union[str, bytes, PurePath]
20-
else:
21-
_Path = Union[str, bytes]
22-
23-
_E = TypeVar('_E', bound=_Element)
24-
_K = TypeVar('_K', bound=Key)
9+
_E = typeVar('_E', bound=_Element)
2510

2611
def enable_debug_trace(enabled: bool = ...) -> None: ...
2712
def init() -> None: ...
2813
def shutdown() -> None: ...
2914
def cleanup_callbacks() -> None: ...
3015
def register_default_callbacks() -> None: ...
3116
def register_callbacks(
32-
input_match_callback: Callable[[bytes], bool],
33-
input_open_callback: Callable[[bytes], Any],
34-
input_read_callback: Callable[[Any, memoryview], int],
35-
input_close_callback: Callable[[Any], None],
17+
input_match_callback: Callable[[bytes], bool],
18+
input_open_callback: Callable[[bytes], Any],
19+
input_read_callback: Callable[[Any, memoryview], int],
20+
input_close_callback: Callable[[Any], None],
3621
) -> None: ...
3722
@overload
3823
def base64_default_line_size() -> int: ...
3924
@overload
4025
def base64_default_line_size(size: int) -> None: ...
4126

4227
class EncryptionContext:
43-
key: Optional[Key]
44-
def __init__(self, manager: Optional[KeysManager] = None) -> None: ...
28+
key: Key | None
29+
def __init__(self, manager: KeysManager | None = ...) -> None: ...
4530
def decrypt(self, node: _Element) -> _Element: ...
4631
def encrypt_binary(self, template: _E, data: bytes) -> _E: ...
4732
def encrypt_uri(self, template: _E, uri: str) -> _E: ...
@@ -54,30 +39,30 @@ class InternalError(Error): ...
5439
class Key:
5540
name: str
5641
@classmethod
57-
def from_binary_data(cls: Type[_K], klass: KeyData, data: AnyStr) -> _K: ...
42+
def from_binary_data(cls: type[Self], klass: KeyData, data: AnyStr) -> Self: ...
5843
@classmethod
59-
def from_binary_file(cls: Type[_K], klass: KeyData, filename: _Path) -> _K: ...
44+
def from_binary_file(cls: type[Self], klass: KeyData, filename: StrOrBytesPath) -> Self: ...
6045
@classmethod
61-
def from_file(cls: Type[_K], file: Union[_Path, IO[AnyStr]], format: int, password: Optional[str] = ...) -> _K: ...
46+
def from_file(cls: type[Self], file: GenericPath | IO[AnyStr], format: int, password: str | None = ...) -> Self: ...
6247
@classmethod
63-
def from_memory(cls: Type[_K], data: AnyStr, format: int, password: Optional[str] = ...) -> _K: ...
48+
def from_memory(cls: type[Self], data: AnyStr, format: int, password: str | None = ...) -> Self: ...
6449
@classmethod
65-
def generate(cls: Type[_K], klass: KeyData, size: int, type: int) -> _K: ...
66-
def load_cert_from_file(self, file: Union[_Path, IO[AnyStr]], format: int) -> None: ...
50+
def generate(cls: type[Self], klass: KeyData, size: int, type: int) -> Self: ...
51+
def load_cert_from_file(self, file: GenericPath | IO[AnyStr], format: int) -> None: ...
6752
def load_cert_from_memory(self, data: AnyStr, format: int) -> None: ...
68-
def __copy__(self: _K) -> _K: ...
69-
def __deepcopy__(self: _K) -> _K: ...
53+
def __copy__(self: Self) -> Self: ...
54+
def __deepcopy__(self: Self) -> Self: ...
7055

7156
class KeysManager:
7257
def add_key(self, key: Key) -> None: ...
73-
def load_cert(self, filename: _Path, format: int, type: int) -> None: ...
58+
def load_cert(self, filename: StrOrBytesPath, format: int, type: int) -> None: ...
7459
def load_cert_from_memory(self, data: AnyStr, format: int, type: int) -> None: ...
7560

7661
class SignatureContext:
77-
key: Optional[Key]
62+
key: Key | None
7863
def enable_reference_transform(self, transform: Transform) -> None: ...
7964
def enable_signature_transform(self, transform: Transform) -> None: ...
80-
def register_id(self, node: _Element, id_attr: str = "ID", id_ns: Optional[str] = None) -> None: ...
65+
def register_id(self, node: _Element, id_attr: str = ..., id_ns: str | None = ...) -> None: ...
8166
def set_enabled_key_data(self, keydata_list: Iterable[KeyData]) -> None: ...
8267
def sign(self, node: _Element) -> None: ...
8368
def sign_binary(self, bytes: bytes, transform: Transform) -> bytes: ...

0 commit comments

Comments
 (0)