From 8640c1a0fc27ca804b3c133253bd0f239fe77868 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 3 Jan 2025 11:28:57 -0500 Subject: [PATCH] Implement fixes to ruff check --preview (#12230) --- src/cryptography/fernet.py | 3 +- .../hazmat/bindings/_rust/ocsp.pyi | 4 +- .../hazmat/bindings/_rust/pkcs12.pyi | 3 +- .../hazmat/bindings/_rust/pkcs7.pyi | 12 +-- .../hazmat/bindings/_rust/x509.pyi | 9 ++- .../hazmat/bindings/openssl/binding.py | 3 +- .../hazmat/primitives/ciphers/base.py | 2 +- .../hazmat/primitives/kdf/concatkdf.py | 3 +- .../hazmat/primitives/kdf/kbkdf.py | 3 +- src/cryptography/hazmat/primitives/padding.py | 6 +- .../hazmat/primitives/serialization/pkcs12.py | 3 +- .../hazmat/primitives/serialization/pkcs7.py | 5 +- src/cryptography/utils.py | 6 +- src/cryptography/x509/base.py | 3 +- src/cryptography/x509/extensions.py | 73 ++++++++----------- src/cryptography/x509/name.py | 13 ++-- src/cryptography/x509/ocsp.py | 4 +- tests/x509/test_x509.py | 2 +- 18 files changed, 79 insertions(+), 78 deletions(-) diff --git a/src/cryptography/fernet.py b/src/cryptography/fernet.py index 868ecb277789..c6744ae384e3 100644 --- a/src/cryptography/fernet.py +++ b/src/cryptography/fernet.py @@ -9,6 +9,7 @@ import os import time import typing +from collections.abc import Iterable from cryptography import utils from cryptography.exceptions import InvalidSignature @@ -168,7 +169,7 @@ def _decrypt_data( class MultiFernet: - def __init__(self, fernets: typing.Iterable[Fernet]): + def __init__(self, fernets: Iterable[Fernet]): fernets = list(fernets) if not fernets: raise ValueError( diff --git a/src/cryptography/hazmat/bindings/_rust/ocsp.pyi b/src/cryptography/hazmat/bindings/_rust/ocsp.pyi index e4321bec2ad2..103e96c1f117 100644 --- a/src/cryptography/hazmat/bindings/_rust/ocsp.pyi +++ b/src/cryptography/hazmat/bindings/_rust/ocsp.pyi @@ -3,7 +3,7 @@ # for complete details. import datetime -import typing +from collections.abc import Iterator from cryptography import x509 from cryptography.hazmat.primitives import hashes, serialization @@ -25,7 +25,7 @@ class OCSPRequest: class OCSPResponse: @property - def responses(self) -> typing.Iterator[OCSPSingleResponse]: ... + def responses(self) -> Iterator[OCSPSingleResponse]: ... @property def response_status(self) -> ocsp.OCSPResponseStatus: ... @property diff --git a/src/cryptography/hazmat/bindings/_rust/pkcs12.pyi b/src/cryptography/hazmat/bindings/_rust/pkcs12.pyi index 40514c4623d5..44372a72be40 100644 --- a/src/cryptography/hazmat/bindings/_rust/pkcs12.pyi +++ b/src/cryptography/hazmat/bindings/_rust/pkcs12.pyi @@ -3,6 +3,7 @@ # for complete details. import typing +from collections.abc import Iterable from cryptography import x509 from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes @@ -41,6 +42,6 @@ def serialize_key_and_certificates( name: bytes | None, key: PKCS12PrivateKeyTypes | None, cert: x509.Certificate | None, - cas: typing.Iterable[x509.Certificate | PKCS12Certificate] | None, + cas: Iterable[x509.Certificate | PKCS12Certificate] | None, encryption_algorithm: KeySerializationEncryption, ) -> bytes: ... diff --git a/src/cryptography/hazmat/bindings/_rust/pkcs7.pyi b/src/cryptography/hazmat/bindings/_rust/pkcs7.pyi index 051e90bad050..358b135865a8 100644 --- a/src/cryptography/hazmat/bindings/_rust/pkcs7.pyi +++ b/src/cryptography/hazmat/bindings/_rust/pkcs7.pyi @@ -2,7 +2,7 @@ # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. -import typing +from collections.abc import Iterable from cryptography import x509 from cryptography.hazmat.primitives import serialization @@ -17,30 +17,30 @@ def encrypt_and_serialize( builder: pkcs7.PKCS7EnvelopeBuilder, content_encryption_algorithm: pkcs7.ContentEncryptionAlgorithm, encoding: serialization.Encoding, - options: typing.Iterable[pkcs7.PKCS7Options], + options: Iterable[pkcs7.PKCS7Options], ) -> bytes: ... def sign_and_serialize( builder: pkcs7.PKCS7SignatureBuilder, encoding: serialization.Encoding, - options: typing.Iterable[pkcs7.PKCS7Options], + options: Iterable[pkcs7.PKCS7Options], ) -> bytes: ... def decrypt_der( data: bytes, certificate: x509.Certificate, private_key: rsa.RSAPrivateKey, - options: typing.Iterable[pkcs7.PKCS7Options], + options: Iterable[pkcs7.PKCS7Options], ) -> bytes: ... def decrypt_pem( data: bytes, certificate: x509.Certificate, private_key: rsa.RSAPrivateKey, - options: typing.Iterable[pkcs7.PKCS7Options], + options: Iterable[pkcs7.PKCS7Options], ) -> bytes: ... def decrypt_smime( data: bytes, certificate: x509.Certificate, private_key: rsa.RSAPrivateKey, - options: typing.Iterable[pkcs7.PKCS7Options], + options: Iterable[pkcs7.PKCS7Options], ) -> bytes: ... def load_pem_pkcs7_certificates( data: bytes, diff --git a/src/cryptography/hazmat/bindings/_rust/x509.pyi b/src/cryptography/hazmat/bindings/_rust/x509.pyi index f44506c0852e..540f42d8c906 100644 --- a/src/cryptography/hazmat/bindings/_rust/x509.pyi +++ b/src/cryptography/hazmat/bindings/_rust/x509.pyi @@ -4,6 +4,7 @@ import datetime import typing +from collections.abc import Iterator from cryptography import x509 from cryptography.hazmat.primitives import hashes, serialization @@ -108,7 +109,7 @@ class Certificate: @property def signature_algorithm_parameters( self, - ) -> None | PSS | PKCS1v15 | ECDSA: ... + ) -> PSS | PKCS1v15 | ECDSA | None: ... @property def extensions(self) -> x509.Extensions: ... @property @@ -139,7 +140,7 @@ class CertificateRevocationList: @property def signature_algorithm_parameters( self, - ) -> None | PSS | PKCS1v15 | ECDSA: ... + ) -> PSS | PKCS1v15 | ECDSA | None: ... @property def issuer(self) -> x509.Name: ... @property @@ -162,7 +163,7 @@ class CertificateRevocationList: def __getitem__(self, idx: int) -> x509.RevokedCertificate: ... @typing.overload def __getitem__(self, idx: slice) -> list[x509.RevokedCertificate]: ... - def __iter__(self) -> typing.Iterator[x509.RevokedCertificate]: ... + def __iter__(self) -> Iterator[x509.RevokedCertificate]: ... def is_signature_valid( self, public_key: CertificateIssuerPublicKeyTypes ) -> bool: ... @@ -182,7 +183,7 @@ class CertificateSigningRequest: @property def signature_algorithm_parameters( self, - ) -> None | PSS | PKCS1v15 | ECDSA: ... + ) -> PSS | PKCS1v15 | ECDSA | None: ... @property def extensions(self) -> x509.Extensions: ... @property diff --git a/src/cryptography/hazmat/bindings/openssl/binding.py b/src/cryptography/hazmat/bindings/openssl/binding.py index d4dfeef485d1..7de2c65356bb 100644 --- a/src/cryptography/hazmat/bindings/openssl/binding.py +++ b/src/cryptography/hazmat/bindings/openssl/binding.py @@ -10,6 +10,7 @@ import types import typing import warnings +from collections.abc import Callable import cryptography from cryptography.exceptions import InternalError @@ -35,7 +36,7 @@ def _openssl_assert(ok: bool) -> None: def build_conditional_library( lib: typing.Any, - conditional_names: dict[str, typing.Callable[[], list[str]]], + conditional_names: dict[str, Callable[[], list[str]]], ) -> typing.Any: conditional_lib = types.ModuleType("lib") conditional_lib._original_lib = lib # type: ignore[attr-defined] diff --git a/src/cryptography/hazmat/primitives/ciphers/base.py b/src/cryptography/hazmat/primitives/ciphers/base.py index ebfa8052c8da..21de09487d55 100644 --- a/src/cryptography/hazmat/primitives/ciphers/base.py +++ b/src/cryptography/hazmat/primitives/ciphers/base.py @@ -134,9 +134,9 @@ def decryptor(self): typing.Union[ modes.ModeWithNonce, modes.ModeWithTweak, - None, modes.ECB, modes.ModeWithInitializationVector, + None, ] ] diff --git a/src/cryptography/hazmat/primitives/kdf/concatkdf.py b/src/cryptography/hazmat/primitives/kdf/concatkdf.py index 96d9d4c0df5e..48a4286488dd 100644 --- a/src/cryptography/hazmat/primitives/kdf/concatkdf.py +++ b/src/cryptography/hazmat/primitives/kdf/concatkdf.py @@ -5,6 +5,7 @@ from __future__ import annotations import typing +from collections.abc import Callable from cryptography import utils from cryptography.exceptions import AlreadyFinalized, InvalidKey @@ -31,7 +32,7 @@ def _common_args_checks( def _concatkdf_derive( key_material: bytes, length: int, - auxfn: typing.Callable[[], hashes.HashContext], + auxfn: Callable[[], hashes.HashContext], otherinfo: bytes, ) -> bytes: utils._check_byteslike("key_material", key_material) diff --git a/src/cryptography/hazmat/primitives/kdf/kbkdf.py b/src/cryptography/hazmat/primitives/kdf/kbkdf.py index 802b484c72ae..4d98a2103771 100644 --- a/src/cryptography/hazmat/primitives/kdf/kbkdf.py +++ b/src/cryptography/hazmat/primitives/kdf/kbkdf.py @@ -5,6 +5,7 @@ from __future__ import annotations import typing +from collections.abc import Callable from cryptography import utils from cryptography.exceptions import ( @@ -36,7 +37,7 @@ class CounterLocation(utils.Enum): class _KBKDFDeriver: def __init__( self, - prf: typing.Callable, + prf: Callable, mode: Mode, length: int, rlen: int, diff --git a/src/cryptography/hazmat/primitives/padding.py b/src/cryptography/hazmat/primitives/padding.py index b2a3f1cfffaa..e226ad2532d4 100644 --- a/src/cryptography/hazmat/primitives/padding.py +++ b/src/cryptography/hazmat/primitives/padding.py @@ -5,7 +5,7 @@ from __future__ import annotations import abc -import typing +from collections.abc import Callable from cryptography import utils from cryptography.exceptions import AlreadyFinalized @@ -59,7 +59,7 @@ def _byte_padding_update( def _byte_padding_pad( buffer_: bytes | None, block_size: int, - paddingfn: typing.Callable[[int], bytes], + paddingfn: Callable[[int], bytes], ) -> bytes: if buffer_ is None: raise AlreadyFinalized("Context was already finalized.") @@ -89,7 +89,7 @@ def _byte_unpadding_update( def _byte_unpadding_check( buffer_: bytes | None, block_size: int, - checkfn: typing.Callable[[bytes], int], + checkfn: Callable[[bytes], int], ) -> bytes: if buffer_ is None: raise AlreadyFinalized("Context was already finalized.") diff --git a/src/cryptography/hazmat/primitives/serialization/pkcs12.py b/src/cryptography/hazmat/primitives/serialization/pkcs12.py index 549e1f992d39..bab4d1eabf14 100644 --- a/src/cryptography/hazmat/primitives/serialization/pkcs12.py +++ b/src/cryptography/hazmat/primitives/serialization/pkcs12.py @@ -5,6 +5,7 @@ from __future__ import annotations import typing +from collections.abc import Iterable from cryptography import x509 from cryptography.hazmat.bindings._rust import pkcs12 as rust_pkcs12 @@ -122,7 +123,7 @@ def serialize_key_and_certificates( name: bytes | None, key: PKCS12PrivateKeyTypes | None, cert: x509.Certificate | None, - cas: typing.Iterable[_PKCS12CATypes] | None, + cas: Iterable[_PKCS12CATypes] | None, encryption_algorithm: serialization.KeySerializationEncryption, ) -> bytes: if key is not None and not isinstance( diff --git a/src/cryptography/hazmat/primitives/serialization/pkcs7.py b/src/cryptography/hazmat/primitives/serialization/pkcs7.py index c3818724c0c9..aeb6a035fe22 100644 --- a/src/cryptography/hazmat/primitives/serialization/pkcs7.py +++ b/src/cryptography/hazmat/primitives/serialization/pkcs7.py @@ -10,6 +10,7 @@ import email.policy import io import typing +from collections.abc import Iterable from cryptography import utils, x509 from cryptography.exceptions import UnsupportedAlgorithm, _Reasons @@ -133,7 +134,7 @@ def add_certificate( def sign( self, encoding: serialization.Encoding, - options: typing.Iterable[PKCS7Options], + options: Iterable[PKCS7Options], backend: typing.Any = None, ) -> bytes: if len(self._signers) == 0: @@ -258,7 +259,7 @@ def set_content_encryption_algorithm( def encrypt( self, encoding: serialization.Encoding, - options: typing.Iterable[PKCS7Options], + options: Iterable[PKCS7Options], ) -> bytes: if len(self._recipients) == 0: raise ValueError("Must have at least one recipient") diff --git a/src/cryptography/utils.py b/src/cryptography/utils.py index 706d0ae4cbd7..67b50755ed25 100644 --- a/src/cryptography/utils.py +++ b/src/cryptography/utils.py @@ -7,8 +7,8 @@ import enum import sys import types -import typing import warnings +from collections.abc import Callable, Sequence # We use a UserWarning subclass, instead of DeprecationWarning, because CPython @@ -81,7 +81,7 @@ def __delattr__(self, attr: str) -> None: delattr(self._module, attr) - def __dir__(self) -> typing.Sequence[str]: + def __dir__(self) -> Sequence[str]: return ["_module", *dir(self._module)] @@ -102,7 +102,7 @@ def deprecated( return dv -def cached_property(func: typing.Callable) -> property: +def cached_property(func: Callable) -> property: cached_name = f"_cached_{func}" sentinel = object() diff --git a/src/cryptography/x509/base.py b/src/cryptography/x509/base.py index 25b317af626f..26687912a7cb 100644 --- a/src/cryptography/x509/base.py +++ b/src/cryptography/x509/base.py @@ -9,6 +9,7 @@ import os import typing import warnings +from collections.abc import Iterable from cryptography import utils from cryptography.hazmat.bindings._rust import x509 as rust_x509 @@ -131,7 +132,7 @@ def __hash__(self) -> int: class Attributes: def __init__( self, - attributes: typing.Iterable[Attribute], + attributes: Iterable[Attribute], ) -> None: self._attributes = list(attributes) diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index fc3e7730eca0..1b674145e9d7 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -9,6 +9,7 @@ import hashlib import ipaddress import typing +from collections.abc import Iterable, Iterator from cryptography import utils from cryptography.hazmat.bindings._rust import asn1 @@ -109,9 +110,7 @@ def public_bytes(self) -> bytes: class Extensions: - def __init__( - self, extensions: typing.Iterable[Extension[ExtensionType]] - ) -> None: + def __init__(self, extensions: Iterable[Extension[ExtensionType]]) -> None: self._extensions = list(extensions) def get_extension_for_oid( @@ -182,7 +181,7 @@ class AuthorityKeyIdentifier(ExtensionType): def __init__( self, key_identifier: bytes | None, - authority_cert_issuer: typing.Iterable[GeneralName] | None, + authority_cert_issuer: Iterable[GeneralName] | None, authority_cert_serial_number: int | None, ) -> None: if (authority_cert_issuer is None) != ( @@ -323,9 +322,7 @@ def public_bytes(self) -> bytes: class AuthorityInformationAccess(ExtensionType): oid = ExtensionOID.AUTHORITY_INFORMATION_ACCESS - def __init__( - self, descriptions: typing.Iterable[AccessDescription] - ) -> None: + def __init__(self, descriptions: Iterable[AccessDescription]) -> None: descriptions = list(descriptions) if not all(isinstance(x, AccessDescription) for x in descriptions): raise TypeError( @@ -356,9 +353,7 @@ def public_bytes(self) -> bytes: class SubjectInformationAccess(ExtensionType): oid = ExtensionOID.SUBJECT_INFORMATION_ACCESS - def __init__( - self, descriptions: typing.Iterable[AccessDescription] - ) -> None: + def __init__(self, descriptions: Iterable[AccessDescription]) -> None: descriptions = list(descriptions) if not all(isinstance(x, AccessDescription) for x in descriptions): raise TypeError( @@ -506,7 +501,7 @@ class CRLDistributionPoints(ExtensionType): oid = ExtensionOID.CRL_DISTRIBUTION_POINTS def __init__( - self, distribution_points: typing.Iterable[DistributionPoint] + self, distribution_points: Iterable[DistributionPoint] ) -> None: distribution_points = list(distribution_points) if not all( @@ -543,7 +538,7 @@ class FreshestCRL(ExtensionType): oid = ExtensionOID.FRESHEST_CRL def __init__( - self, distribution_points: typing.Iterable[DistributionPoint] + self, distribution_points: Iterable[DistributionPoint] ) -> None: distribution_points = list(distribution_points) if not all( @@ -579,10 +574,10 @@ def public_bytes(self) -> bytes: class DistributionPoint: def __init__( self, - full_name: typing.Iterable[GeneralName] | None, + full_name: Iterable[GeneralName] | None, relative_name: RelativeDistinguishedName | None, reasons: frozenset[ReasonFlags] | None, - crl_issuer: typing.Iterable[GeneralName] | None, + crl_issuer: Iterable[GeneralName] | None, ) -> None: if full_name and relative_name: raise ValueError( @@ -824,7 +819,7 @@ def public_bytes(self) -> bytes: class CertificatePolicies(ExtensionType): oid = ExtensionOID.CERTIFICATE_POLICIES - def __init__(self, policies: typing.Iterable[PolicyInformation]) -> None: + def __init__(self, policies: Iterable[PolicyInformation]) -> None: policies = list(policies) if not all(isinstance(x, PolicyInformation) for x in policies): raise TypeError( @@ -856,7 +851,7 @@ class PolicyInformation: def __init__( self, policy_identifier: ObjectIdentifier, - policy_qualifiers: typing.Iterable[str | UserNotice] | None, + policy_qualifiers: Iterable[str | UserNotice] | None, ) -> None: if not isinstance(policy_identifier, ObjectIdentifier): raise TypeError("policy_identifier must be an ObjectIdentifier") @@ -956,7 +951,7 @@ class NoticeReference: def __init__( self, organization: str | None, - notice_numbers: typing.Iterable[int], + notice_numbers: Iterable[int], ) -> None: self._organization = organization notice_numbers = list(notice_numbers) @@ -995,7 +990,7 @@ def notice_numbers(self) -> list[int]: class ExtendedKeyUsage(ExtensionType): oid = ExtensionOID.EXTENDED_KEY_USAGE - def __init__(self, usages: typing.Iterable[ObjectIdentifier]) -> None: + def __init__(self, usages: Iterable[ObjectIdentifier]) -> None: usages = list(usages) if not all(isinstance(x, ObjectIdentifier) for x in usages): raise TypeError( @@ -1063,7 +1058,7 @@ def public_bytes(self) -> bytes: class TLSFeature(ExtensionType): oid = ExtensionOID.TLS_FEATURE - def __init__(self, features: typing.Iterable[TLSFeatureType]) -> None: + def __init__(self, features: Iterable[TLSFeatureType]) -> None: features = list(features) if ( not all(isinstance(x, TLSFeatureType) for x in features) @@ -1278,8 +1273,8 @@ class NameConstraints(ExtensionType): def __init__( self, - permitted_subtrees: typing.Iterable[GeneralName] | None, - excluded_subtrees: typing.Iterable[GeneralName] | None, + permitted_subtrees: Iterable[GeneralName] | None, + excluded_subtrees: Iterable[GeneralName] | None, ) -> None: if permitted_subtrees is not None: permitted_subtrees = list(permitted_subtrees) @@ -1327,11 +1322,11 @@ def __eq__(self, other: object) -> bool: and self.permitted_subtrees == other.permitted_subtrees ) - def _validate_tree(self, tree: typing.Iterable[GeneralName]) -> None: + def _validate_tree(self, tree: Iterable[GeneralName]) -> None: self._validate_ip_name(tree) self._validate_dns_name(tree) - def _validate_ip_name(self, tree: typing.Iterable[GeneralName]) -> None: + def _validate_ip_name(self, tree: Iterable[GeneralName]) -> None: if any( isinstance(name, IPAddress) and not isinstance( @@ -1344,7 +1339,7 @@ def _validate_ip_name(self, tree: typing.Iterable[GeneralName]) -> None: " IPv6Network object" ) - def _validate_dns_name(self, tree: typing.Iterable[GeneralName]) -> None: + def _validate_dns_name(self, tree: Iterable[GeneralName]) -> None: if any( isinstance(name, DNSName) and "*" in name.value for name in tree ): @@ -1437,7 +1432,7 @@ def __hash__(self) -> int: class GeneralNames: - def __init__(self, general_names: typing.Iterable[GeneralName]) -> None: + def __init__(self, general_names: Iterable[GeneralName]) -> None: general_names = list(general_names) if not all(isinstance(x, GeneralName) for x in general_names): raise TypeError( @@ -1519,7 +1514,7 @@ def __hash__(self) -> int: class SubjectAlternativeName(ExtensionType): oid = ExtensionOID.SUBJECT_ALTERNATIVE_NAME - def __init__(self, general_names: typing.Iterable[GeneralName]) -> None: + def __init__(self, general_names: Iterable[GeneralName]) -> None: self._general_names = GeneralNames(general_names) __len__, __iter__, __getitem__ = _make_sequence_methods("_general_names") @@ -1591,7 +1586,7 @@ def public_bytes(self) -> bytes: class IssuerAlternativeName(ExtensionType): oid = ExtensionOID.ISSUER_ALTERNATIVE_NAME - def __init__(self, general_names: typing.Iterable[GeneralName]) -> None: + def __init__(self, general_names: Iterable[GeneralName]) -> None: self._general_names = GeneralNames(general_names) __len__, __iter__, __getitem__ = _make_sequence_methods("_general_names") @@ -1663,7 +1658,7 @@ def public_bytes(self) -> bytes: class CertificateIssuer(ExtensionType): oid = CRLEntryExtensionOID.CERTIFICATE_ISSUER - def __init__(self, general_names: typing.Iterable[GeneralName]) -> None: + def __init__(self, general_names: Iterable[GeneralName]) -> None: self._general_names = GeneralNames(general_names) __len__, __iter__, __getitem__ = _make_sequence_methods("_general_names") @@ -1802,9 +1797,7 @@ class PrecertificateSignedCertificateTimestamps(ExtensionType): def __init__( self, - signed_certificate_timestamps: typing.Iterable[ - SignedCertificateTimestamp - ], + signed_certificate_timestamps: Iterable[SignedCertificateTimestamp], ) -> None: signed_certificate_timestamps = list(signed_certificate_timestamps) if not all( @@ -1845,9 +1838,7 @@ class SignedCertificateTimestamps(ExtensionType): def __init__( self, - signed_certificate_timestamps: typing.Iterable[ - SignedCertificateTimestamp - ], + signed_certificate_timestamps: Iterable[SignedCertificateTimestamp], ) -> None: signed_certificate_timestamps = list(signed_certificate_timestamps) if not all( @@ -1915,7 +1906,7 @@ def public_bytes(self) -> bytes: class OCSPAcceptableResponses(ExtensionType): oid = OCSPExtensionOID.ACCEPTABLE_RESPONSES - def __init__(self, responses: typing.Iterable[ObjectIdentifier]) -> None: + def __init__(self, responses: Iterable[ObjectIdentifier]) -> None: responses = list(responses) if any(not isinstance(r, ObjectIdentifier) for r in responses): raise TypeError("All responses must be ObjectIdentifiers") @@ -1934,7 +1925,7 @@ def __hash__(self) -> int: def __repr__(self) -> str: return f"" - def __iter__(self) -> typing.Iterator[ObjectIdentifier]: + def __iter__(self) -> Iterator[ObjectIdentifier]: return iter(self._responses) def public_bytes(self) -> bytes: @@ -1946,7 +1937,7 @@ class IssuingDistributionPoint(ExtensionType): def __init__( self, - full_name: typing.Iterable[GeneralName] | None, + full_name: Iterable[GeneralName] | None, relative_name: RelativeDistinguishedName | None, only_contains_user_certs: bool, only_contains_ca_certs: bool, @@ -2224,8 +2215,8 @@ class ProfessionInfo: def __init__( self, naming_authority: NamingAuthority | None, - profession_items: typing.Iterable[str], - profession_oids: typing.Iterable[ObjectIdentifier] | None, + profession_items: Iterable[str], + profession_oids: Iterable[ObjectIdentifier] | None, registration_number: str | None, add_profession_info: bytes | None, ) -> None: @@ -2328,7 +2319,7 @@ def __init__( self, admission_authority: GeneralName | None, naming_authority: NamingAuthority | None, - profession_infos: typing.Iterable[ProfessionInfo], + profession_infos: Iterable[ProfessionInfo], ) -> None: if admission_authority is not None and not isinstance( admission_authority, GeneralName @@ -2398,7 +2389,7 @@ class Admissions(ExtensionType): def __init__( self, authority: GeneralName | None, - admissions: typing.Iterable[Admission], + admissions: Iterable[Admission], ) -> None: if authority is not None and not isinstance(authority, GeneralName): raise TypeError("authority must be a GeneralName") diff --git a/src/cryptography/x509/name.py b/src/cryptography/x509/name.py index 84e568d7514c..5f827818c254 100644 --- a/src/cryptography/x509/name.py +++ b/src/cryptography/x509/name.py @@ -9,6 +9,7 @@ import sys import typing import warnings +from collections.abc import Iterable, Iterator from cryptography import utils from cryptography.hazmat.bindings._rust import x509 as rust_x509 @@ -225,7 +226,7 @@ def __repr__(self) -> str: class RelativeDistinguishedName: - def __init__(self, attributes: typing.Iterable[NameAttribute]): + def __init__(self, attributes: Iterable[NameAttribute]): attributes = list(attributes) if not attributes: raise ValueError("a relative distinguished name cannot be empty") @@ -268,7 +269,7 @@ def __eq__(self, other: object) -> bool: def __hash__(self) -> int: return hash(self._attribute_set) - def __iter__(self) -> typing.Iterator[NameAttribute]: + def __iter__(self) -> Iterator[NameAttribute]: return iter(self._attributes) def __len__(self) -> int: @@ -280,16 +281,16 @@ def __repr__(self) -> str: class Name: @typing.overload - def __init__(self, attributes: typing.Iterable[NameAttribute]) -> None: ... + def __init__(self, attributes: Iterable[NameAttribute]) -> None: ... @typing.overload def __init__( - self, attributes: typing.Iterable[RelativeDistinguishedName] + self, attributes: Iterable[RelativeDistinguishedName] ) -> None: ... def __init__( self, - attributes: typing.Iterable[NameAttribute | RelativeDistinguishedName], + attributes: Iterable[NameAttribute | RelativeDistinguishedName], ) -> None: attributes = list(attributes) if all(isinstance(x, NameAttribute) for x in attributes): @@ -357,7 +358,7 @@ def __hash__(self) -> int: # for you, consider optimizing! return hash(tuple(self._attributes)) - def __iter__(self) -> typing.Iterator[NameAttribute]: + def __iter__(self) -> Iterator[NameAttribute]: for rdn in self._attributes: yield from rdn diff --git a/src/cryptography/x509/ocsp.py b/src/cryptography/x509/ocsp.py index 5a011c412ad3..bae562182fe5 100644 --- a/src/cryptography/x509/ocsp.py +++ b/src/cryptography/x509/ocsp.py @@ -5,7 +5,7 @@ from __future__ import annotations import datetime -import typing +from collections.abc import Iterable from cryptography import utils, x509 from cryptography.hazmat.bindings._rust import ocsp @@ -280,7 +280,7 @@ def responder_id( ) def certificates( - self, certs: typing.Iterable[x509.Certificate] + self, certs: Iterable[x509.Certificate] ) -> OCSPResponseBuilder: if self._certs is not None: raise ValueError("certificates may only be set once") diff --git a/tests/x509/test_x509.py b/tests/x509/test_x509.py index 48278584392c..f54a8fa2ec59 100644 --- a/tests/x509/test_x509.py +++ b/tests/x509/test_x509.py @@ -1148,7 +1148,7 @@ def test_tbs_precertificate_bytes_duplicate_extensions_raises( with pytest.raises( x509.DuplicateExtension, - match="Duplicate 2.5.29.19 extension found", + match=r"Duplicate 2\.5\.29\.19 extension found", ): cert.tbs_precertificate_bytes