Skip to content

Commit f81c075

Browse files
alexshcheklein
andauthored
Backport mypy fixes for release (#12930)
* mypy cleanups for Python 3.8 (#12928) should unblock #12927 * fix typing on release.py with older python (#12929) * fix(x509): use backward compatible syntax for types (#12927) * fix(x509): use backward compatible syntax for types * add Python 3.8 flake to ci * Backport mypy fixes for release * sigh * sigh --------- Co-authored-by: Ivan Shcheklein <shcheklein@gmail.com>
1 parent 8ea28e0 commit f81c075

File tree

11 files changed

+36
-24
lines changed

11 files changed

+36
-24
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
PYTHON:
27+
- {VERSION: "3.8", NOXSESSION: "flake"}
2728
- {VERSION: "3.13", NOXSESSION: "flake"}
2829
- {VERSION: "3.13", NOXSESSION: "rust"}
2930
- {VERSION: "3.12", NOXSESSION: "docs", OPENSSL: {TYPE: "openssl", VERSION: "3.5.0"}}

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
.. _v45-0-2:
5+
6+
45.0.2 - 2025-05-17
7+
~~~~~~~~~~~~~~~~~~~
8+
9+
* Fixed using ``mypy`` with ``cryptography`` on older versions of Python.
10+
411
.. _v45-0-1:
512

613
45.0.1 - 2025-05-17

noxfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
import nox
1717

18-
try:
18+
if sys.version_info >= (3, 11):
1919
import tomllib
20-
except ImportError:
21-
import tomli as tomllib # type: ignore[import-not-found,no-redef]
20+
else:
21+
import tomli as tomllib
2222

2323
nox.options.reuse_existing_virtualenvs = True
2424
nox.options.default_venv_backend = "uv|virtualenv"

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ build-backend = "maturin"
1515

1616
[project]
1717
name = "cryptography"
18-
version = "45.0.1"
18+
version = "45.0.2"
1919
authors = [
2020
{ name = "The Python Cryptographic Authority and individual contributors", email = "cryptography-dev@python.org" },
2121
]
@@ -65,7 +65,7 @@ ssh = ["bcrypt >=3.1.5"]
6565
# All the following are used for our own testing.
6666
nox = ["nox >=2024.04.15", "nox[uv] >=2024.03.02; python_version >= '3.8'"]
6767
test = [
68-
"cryptography_vectors==45.0.1",
68+
"cryptography_vectors==45.0.2",
6969
"pytest >=7.4.0",
7070
"pytest-benchmark >=4.0",
7171
"pytest-cov >=2.10.1",

release.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
import pathlib
66
import re
77
import subprocess
8+
import sys
89

910
import click
10-
import tomllib
1111
from packaging.version import Version
1212

13+
if sys.version_info >= (3, 11):
14+
import tomllib
15+
else:
16+
import tomli as tomllib
17+
1318

1419
def run(*args: str) -> None:
1520
print(f"[running] {list(args)}")

src/cryptography/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"__version__",
1111
]
1212

13-
__version__ = "45.0.1"
13+
__version__ = "45.0.2"
1414

1515

1616
__author__ = "The Python Cryptographic Authority and individual contributors"

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ class Criticality:
229229
AGNOSTIC: Criticality
230230
NON_CRITICAL: Criticality
231231

232-
type MaybeExtensionValidatorCallback[T: x509.ExtensionType] = typing.Callable[
232+
T = typing.TypeVar("T", contravariant=True, bound=x509.ExtensionType)
233+
234+
MaybeExtensionValidatorCallback = typing.Callable[
233235
[
234236
Policy,
235237
x509.Certificate,
@@ -238,12 +240,10 @@ type MaybeExtensionValidatorCallback[T: x509.ExtensionType] = typing.Callable[
238240
None,
239241
]
240242

241-
type PresentExtensionValidatorCallback[T: x509.ExtensionType] = (
242-
typing.Callable[
243-
[Policy, x509.Certificate, T],
244-
None,
245-
]
246-
)
243+
PresentExtensionValidatorCallback = typing.Callable[
244+
[Policy, x509.Certificate, T],
245+
None,
246+
]
247247

248248
class ExtensionPolicy:
249249
@staticmethod
@@ -255,13 +255,13 @@ class ExtensionPolicy:
255255
def require_not_present(
256256
self, extension_type: type[x509.ExtensionType]
257257
) -> ExtensionPolicy: ...
258-
def may_be_present[T: x509.ExtensionType](
258+
def may_be_present(
259259
self,
260260
extension_type: type[T],
261261
criticality: Criticality,
262262
validator: MaybeExtensionValidatorCallback[T] | None,
263263
) -> ExtensionPolicy: ...
264-
def require_present[T: x509.ExtensionType](
264+
def require_present(
265265
self,
266266
extension_type: type[T],
267267
criticality: Criticality,

src/cryptography/hazmat/primitives/serialization/ssh.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def load_public(
616616
_, data = load_application(data)
617617
return public_key, data
618618

619-
def get_public(self, data: memoryview) -> typing.Never:
619+
def get_public(self, data: memoryview) -> typing.NoReturn:
620620
# Confusingly `get_public` is an entry point used by private key
621621
# loading.
622622
raise UnsupportedAlgorithm(
@@ -642,7 +642,7 @@ def load_public(
642642
_, data = load_application(data)
643643
return public_key, data
644644

645-
def get_public(self, data: memoryview) -> typing.Never:
645+
def get_public(self, data: memoryview) -> typing.NoReturn:
646646
# Confusingly `get_public` is an entry point used by private key
647647
# loading.
648648
raise UnsupportedAlgorithm(
@@ -716,10 +716,7 @@ def load_ssh_private_key(
716716
pubfields, pubdata = kformat.get_public(pubdata)
717717
_check_empty(pubdata)
718718

719-
if (ciphername, kdfname) != (
720-
_NONE,
721-
_NONE,
722-
): # type: ignore[comparison-overlap]
719+
if ciphername != _NONE or kdfname != _NONE:
723720
ciphername_bytes = ciphername.tobytes()
724721
if ciphername_bytes not in _SSH_CIPHERS:
725722
raise UnsupportedAlgorithm(

tests/x509/verification/test_limbo.py

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

5+
from __future__ import annotations
6+
57
import datetime
68
import ipaddress
79
import json

vectors/cryptography_vectors/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"__version__",
77
]
88

9-
__version__ = "45.0.1"
9+
__version__ = "45.0.2"

vectors/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "cryptography_vectors"
7-
version = "45.0.1"
7+
version = "45.0.2"
88
authors = [
99
{name = "The Python Cryptographic Authority and individual contributors", email = "cryptography-dev@python.org"}
1010
]

0 commit comments

Comments
 (0)