Skip to content

Commit 1c32edc

Browse files
authored
Silencing mmap mypy warning on windows (#11570)
* silencing the mmap mypy warning on windows even though the lib doesn't exist on this platform * better way without coverage issues * trying with pragma no cover :( * using type: ignore * another test with pragma: no cover * testing type: ignore with specific exclusions
1 parent 2bf6ed8 commit 1c32edc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tests/hazmat/primitives/test_aead.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def _aead_supported(cls):
3737
return False
3838

3939

40-
def large_mmap():
41-
return mmap.mmap(-1, 2**32, prot=mmap.PROT_READ)
40+
def large_mmap(length: int = 2**32):
41+
# Silencing mypy prot argument warning on Windows, even though this
42+
# function is only used in non-Windows-based tests.
43+
return mmap.mmap(-1, length, prot=mmap.PROT_READ) # type: ignore[call-arg,attr-defined,unused-ignore]
4244

4345

4446
@pytest.mark.skipif(

tests/hazmat/primitives/test_ciphers.py

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

55

66
import binascii
7-
import mmap
87
import os
98
import sys
109

@@ -20,6 +19,7 @@
2019
)
2120

2221
from ...utils import load_nist_vectors, load_vectors_from_file
22+
from .test_aead import large_mmap
2323

2424

2525
def test_deprecated_ciphers_import_with_warning():
@@ -255,7 +255,7 @@ def test_update_into_buffer_too_small_gcm(self, backend):
255255
sys.platform not in {"linux", "darwin"}, reason="mmap required"
256256
)
257257
def test_update_auto_chunking():
258-
large_data = mmap.mmap(-1, 2**29 + 2**20, prot=mmap.PROT_READ)
258+
large_data = large_mmap(length=2**29 + 2**20)
259259

260260
key = b"\x00" * 16
261261
c = ciphers.Cipher(AES(key), modes.ECB())

0 commit comments

Comments
 (0)