_ModuleWithDeprecations should inherit from types.ModuleType (#6267) (#6268)

* _ModuleWithDeprecations should inherit from types.ModuleType (#6267)

Update utils.py

* fix typos reported by black

* flake8 fix

* Test should fail when int_from_bytes will be removed.

Because this test would become pointless then.
This commit is contained in:
Sándor Jenei 2021-09-13 11:08:34 +02:00 committed by GitHub
parent 7b5634911c
commit bacf23f3ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import abc
import enum
import inspect
import sys
import types
import typing
import warnings
@ -113,8 +114,9 @@ class _DeprecatedValue(object):
self.warning_class = warning_class
class _ModuleWithDeprecations(object):
class _ModuleWithDeprecations(types.ModuleType):
def __init__(self, module):
super().__init__(module.__name__)
self.__dict__["_module"] = module
def __getattr__(self, attr):

View file

@ -4,6 +4,7 @@
import binascii
import inspect
import os
import textwrap
@ -12,6 +13,7 @@ import pretend
import pytest
import cryptography
import cryptography.utils
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
import cryptography_vectors
@ -4444,3 +4446,13 @@ def test_raises_unsupported_algorithm():
"An error.", _Reasons.BACKEND_MISSING_INTERFACE
)
assert exc_info.type is UnsupportedAlgorithm
def test_inspect_deprecated_module():
# Check if inspection is supported by _ModuleWithDeprecations.
assert isinstance(
cryptography.utils, cryptography.utils._ModuleWithDeprecations
)
source_file = inspect.getsourcefile(cryptography.utils)
assert isinstance(source_file, str)
assert source_file.endswith("utils.py")