Skip to content

Commit 8640c1a

Browse files
authored
Implement fixes to ruff check --preview (#12230)
1 parent df9c968 commit 8640c1a

File tree

18 files changed

+79
-78
lines changed

18 files changed

+79
-78
lines changed

src/cryptography/fernet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import time
1111
import typing
12+
from collections.abc import Iterable
1213

1314
from cryptography import utils
1415
from cryptography.exceptions import InvalidSignature
@@ -168,7 +169,7 @@ def _decrypt_data(
168169

169170

170171
class MultiFernet:
171-
def __init__(self, fernets: typing.Iterable[Fernet]):
172+
def __init__(self, fernets: Iterable[Fernet]):
172173
fernets = list(fernets)
173174
if not fernets:
174175
raise ValueError(

src/cryptography/hazmat/bindings/_rust/ocsp.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# for complete details.
44

55
import datetime
6-
import typing
6+
from collections.abc import Iterator
77

88
from cryptography import x509
99
from cryptography.hazmat.primitives import hashes, serialization
@@ -25,7 +25,7 @@ class OCSPRequest:
2525

2626
class OCSPResponse:
2727
@property
28-
def responses(self) -> typing.Iterator[OCSPSingleResponse]: ...
28+
def responses(self) -> Iterator[OCSPSingleResponse]: ...
2929
@property
3030
def response_status(self) -> ocsp.OCSPResponseStatus: ...
3131
@property

src/cryptography/hazmat/bindings/_rust/pkcs12.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# for complete details.
44

55
import typing
6+
from collections.abc import Iterable
67

78
from cryptography import x509
89
from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes
@@ -41,6 +42,6 @@ def serialize_key_and_certificates(
4142
name: bytes | None,
4243
key: PKCS12PrivateKeyTypes | None,
4344
cert: x509.Certificate | None,
44-
cas: typing.Iterable[x509.Certificate | PKCS12Certificate] | None,
45+
cas: Iterable[x509.Certificate | PKCS12Certificate] | None,
4546
encryption_algorithm: KeySerializationEncryption,
4647
) -> bytes: ...

src/cryptography/hazmat/bindings/_rust/pkcs7.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
33
# for complete details.
44

5-
import typing
5+
from collections.abc import Iterable
66

77
from cryptography import x509
88
from cryptography.hazmat.primitives import serialization
@@ -17,30 +17,30 @@ def encrypt_and_serialize(
1717
builder: pkcs7.PKCS7EnvelopeBuilder,
1818
content_encryption_algorithm: pkcs7.ContentEncryptionAlgorithm,
1919
encoding: serialization.Encoding,
20-
options: typing.Iterable[pkcs7.PKCS7Options],
20+
options: Iterable[pkcs7.PKCS7Options],
2121
) -> bytes: ...
2222
def sign_and_serialize(
2323
builder: pkcs7.PKCS7SignatureBuilder,
2424
encoding: serialization.Encoding,
25-
options: typing.Iterable[pkcs7.PKCS7Options],
25+
options: Iterable[pkcs7.PKCS7Options],
2626
) -> bytes: ...
2727
def decrypt_der(
2828
data: bytes,
2929
certificate: x509.Certificate,
3030
private_key: rsa.RSAPrivateKey,
31-
options: typing.Iterable[pkcs7.PKCS7Options],
31+
options: Iterable[pkcs7.PKCS7Options],
3232
) -> bytes: ...
3333
def decrypt_pem(
3434
data: bytes,
3535
certificate: x509.Certificate,
3636
private_key: rsa.RSAPrivateKey,
37-
options: typing.Iterable[pkcs7.PKCS7Options],
37+
options: Iterable[pkcs7.PKCS7Options],
3838
) -> bytes: ...
3939
def decrypt_smime(
4040
data: bytes,
4141
certificate: x509.Certificate,
4242
private_key: rsa.RSAPrivateKey,
43-
options: typing.Iterable[pkcs7.PKCS7Options],
43+
options: Iterable[pkcs7.PKCS7Options],
4444
) -> bytes: ...
4545
def load_pem_pkcs7_certificates(
4646
data: bytes,

src/cryptography/hazmat/bindings/_rust/x509.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import datetime
66
import typing
7+
from collections.abc import Iterator
78

89
from cryptography import x509
910
from cryptography.hazmat.primitives import hashes, serialization
@@ -108,7 +109,7 @@ class Certificate:
108109
@property
109110
def signature_algorithm_parameters(
110111
self,
111-
) -> None | PSS | PKCS1v15 | ECDSA: ...
112+
) -> PSS | PKCS1v15 | ECDSA | None: ...
112113
@property
113114
def extensions(self) -> x509.Extensions: ...
114115
@property
@@ -139,7 +140,7 @@ class CertificateRevocationList:
139140
@property
140141
def signature_algorithm_parameters(
141142
self,
142-
) -> None | PSS | PKCS1v15 | ECDSA: ...
143+
) -> PSS | PKCS1v15 | ECDSA | None: ...
143144
@property
144145
def issuer(self) -> x509.Name: ...
145146
@property
@@ -162,7 +163,7 @@ class CertificateRevocationList:
162163
def __getitem__(self, idx: int) -> x509.RevokedCertificate: ...
163164
@typing.overload
164165
def __getitem__(self, idx: slice) -> list[x509.RevokedCertificate]: ...
165-
def __iter__(self) -> typing.Iterator[x509.RevokedCertificate]: ...
166+
def __iter__(self) -> Iterator[x509.RevokedCertificate]: ...
166167
def is_signature_valid(
167168
self, public_key: CertificateIssuerPublicKeyTypes
168169
) -> bool: ...
@@ -182,7 +183,7 @@ class CertificateSigningRequest:
182183
@property
183184
def signature_algorithm_parameters(
184185
self,
185-
) -> None | PSS | PKCS1v15 | ECDSA: ...
186+
) -> PSS | PKCS1v15 | ECDSA | None: ...
186187
@property
187188
def extensions(self) -> x509.Extensions: ...
188189
@property

src/cryptography/hazmat/bindings/openssl/binding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import types
1111
import typing
1212
import warnings
13+
from collections.abc import Callable
1314

1415
import cryptography
1516
from cryptography.exceptions import InternalError
@@ -35,7 +36,7 @@ def _openssl_assert(ok: bool) -> None:
3536

3637
def build_conditional_library(
3738
lib: typing.Any,
38-
conditional_names: dict[str, typing.Callable[[], list[str]]],
39+
conditional_names: dict[str, Callable[[], list[str]]],
3940
) -> typing.Any:
4041
conditional_lib = types.ModuleType("lib")
4142
conditional_lib._original_lib = lib # type: ignore[attr-defined]

src/cryptography/hazmat/primitives/ciphers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ def decryptor(self):
134134
typing.Union[
135135
modes.ModeWithNonce,
136136
modes.ModeWithTweak,
137-
None,
138137
modes.ECB,
139138
modes.ModeWithInitializationVector,
139+
None,
140140
]
141141
]
142142

src/cryptography/hazmat/primitives/kdf/concatkdf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import typing
8+
from collections.abc import Callable
89

910
from cryptography import utils
1011
from cryptography.exceptions import AlreadyFinalized, InvalidKey
@@ -31,7 +32,7 @@ def _common_args_checks(
3132
def _concatkdf_derive(
3233
key_material: bytes,
3334
length: int,
34-
auxfn: typing.Callable[[], hashes.HashContext],
35+
auxfn: Callable[[], hashes.HashContext],
3536
otherinfo: bytes,
3637
) -> bytes:
3738
utils._check_byteslike("key_material", key_material)

src/cryptography/hazmat/primitives/kdf/kbkdf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import typing
8+
from collections.abc import Callable
89

910
from cryptography import utils
1011
from cryptography.exceptions import (
@@ -36,7 +37,7 @@ class CounterLocation(utils.Enum):
3637
class _KBKDFDeriver:
3738
def __init__(
3839
self,
39-
prf: typing.Callable,
40+
prf: Callable,
4041
mode: Mode,
4142
length: int,
4243
rlen: int,

src/cryptography/hazmat/primitives/padding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
import abc
8-
import typing
8+
from collections.abc import Callable
99

1010
from cryptography import utils
1111
from cryptography.exceptions import AlreadyFinalized
@@ -59,7 +59,7 @@ def _byte_padding_update(
5959
def _byte_padding_pad(
6060
buffer_: bytes | None,
6161
block_size: int,
62-
paddingfn: typing.Callable[[int], bytes],
62+
paddingfn: Callable[[int], bytes],
6363
) -> bytes:
6464
if buffer_ is None:
6565
raise AlreadyFinalized("Context was already finalized.")
@@ -89,7 +89,7 @@ def _byte_unpadding_update(
8989
def _byte_unpadding_check(
9090
buffer_: bytes | None,
9191
block_size: int,
92-
checkfn: typing.Callable[[bytes], int],
92+
checkfn: Callable[[bytes], int],
9393
) -> bytes:
9494
if buffer_ is None:
9595
raise AlreadyFinalized("Context was already finalized.")

0 commit comments

Comments
 (0)