Skip to content

Commit f6b1bff

Browse files
committed
test_x509: Add type annotations
The file now passes `mypy --strict`.
1 parent f0e2825 commit f6b1bff

File tree

2 files changed

+127
-87
lines changed

2 files changed

+127
-87
lines changed

src/mbedtls/x509.pyi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import datetime as dt
88
import enum
99
import sys
1010
from pathlib import Path
11-
from typing import NamedTuple, Sequence, Tuple, Union
11+
from typing import NamedTuple, Sequence, Tuple, Type, TypeVar, Union
1212

1313
from mbedtls.hashlib import Hash as _Hash
1414
from mbedtls.pk import ECC, RSA
@@ -39,18 +39,22 @@ class KeyUsage(enum.IntEnum):
3939
def PEM_to_DER(pem: _PEM) -> _DER: ...
4040
def DER_to_PEM(der: _DER, text: str) -> _PEM: ...
4141

42+
TCertificate = TypeVar("TCertificate", bound=Certificate)
43+
4244
class Certificate(abc.ABC):
4345
@classmethod
44-
def from_buffer(cls, buffer: bytes) -> Certificate: ...
46+
def from_buffer(
47+
cls: Type[TCertificate], buffer: bytes
48+
) -> TCertificate: ...
4549
@classmethod
4650
@abc.abstractmethod
47-
def from_file(cls, path: _Path) -> Certificate: ...
51+
def from_file(cls: Type[TCertificate], path: _Path) -> TCertificate: ...
4852
@classmethod
4953
@abc.abstractmethod
50-
def from_DER(cls, der: _DER) -> Certificate: ...
54+
def from_DER(cls: Type[TCertificate], der: _DER) -> TCertificate: ...
5155
@classmethod
5256
@abc.abstractmethod
53-
def from_PEM(cls, pem: _PEM) -> Certificate: ...
57+
def from_PEM(cls: Type[TCertificate], pem: _PEM) -> TCertificate: ...
5458
def __hash__(self) -> int: ...
5559
def __eq__(self, other: object) -> bool: ...
5660
@abc.abstractmethod
@@ -90,7 +94,7 @@ class CRT(Certificate):
9094
@property
9195
def subject(self) -> str: ...
9296
@property
93-
def subject_public_key(self) -> object: ...
97+
def subject_public_key(self) -> _PKEY: ...
9498
@property
9599
def key_usage(self) -> object: ...
96100
@property

0 commit comments

Comments
 (0)