Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silencing mmap mypy warning on windows #11570

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/hazmat/primitives/test_aead.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def _aead_supported(cls):


def large_mmap():
return mmap.mmap(-1, 2**32, prot=mmap.PROT_READ)
# Silencing mypy warning on Windows, even though mmap doesn't exist. See:
# https://mypy.readthedocs.io/en/stable/common_issues.html#version-and-platform-checks
if sys.platform == "win32":
return mmap.mmap(-1, 2**32)
else:
return mmap.mmap(-1, 2**32, prot=mmap.PROT_READ)


@pytest.mark.skipif(
Expand Down
7 changes: 6 additions & 1 deletion tests/hazmat/primitives/test_ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ def test_update_into_buffer_too_small_gcm(self, backend):
sys.platform not in {"linux", "darwin"}, reason="mmap required"
)
def test_update_auto_chunking():
large_data = mmap.mmap(-1, 2**29 + 2**20, prot=mmap.PROT_READ)
# Silencing mypy warning on Windows, even though mmap doesn't exist. See:
# https://mypy.readthedocs.io/en/stable/common_issues.html#version-and-platform-checks
if sys.platform == "win32":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this will produce coverage issues, since it's never reached.

I wonder if an assert sys.platform in {"linux", "darwin"} would work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen it in the documentation, and tried it, as well as assert sys.platform != "win32", without any success. it seems it only works to silence the whole file 😞

large_data = mmap.mmap(-1, 2**29 + 2**20)
else:
large_data = mmap.mmap(-1, 2**29 + 2**20, prot=mmap.PROT_READ)

key = b"\x00" * 16
c = ciphers.Cipher(AES(key), modes.ECB())
Expand Down
Loading