Repository: pyca/cryptography

Issue:
Circular import error (again) in 3.4.3
Opening a new issue as the old one (https://github.com/pyca/cryptography/issues/5756) wasn't re-opened after my comment:


@reaperhulk

Hi,

still got some circular import problems here with cryptography 3.4.3 :

`AttributeError: partially initialized module 'cryptography.hazmat.primitives.asymmetric.dh' has no attribute 'DHParameters' (most likely due to a circular import)`

reproducer used (gencrypto.py):

```
pip3 install -U cryptography
Collecting cryptography
  Downloading cryptography-3.4.3-cp36-abi3-manylinux2014_x86_64.whl (3.2 MB)
     |████████████████████████████████| 3.2 MB 5.3 MB/s 


python3 gencrypto.py

Traceback (most recent call last):
  File "gencrypto.py", line 2, in <module>
    from cryptography.hazmat.primitives.asymmetric import dh
  File "/home/xxxxx/.local/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py", line 11, in <module>
    from cryptography.hazmat.primitives import serialization
  File "/home/xxxxx/.local/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/__init__.py", line 15, in <module>
    from cryptography.hazmat.primitives.serialization.base import (
  File "/home/xxxxx/.local/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 28, in <module>
    def load_pem_parameters(data: bytes, backend=None) -> dh.DHParameters:
AttributeError: partially initialized module 'cryptography.hazmat.primitives.asymmetric.dh' has no attribute 'DHParameters' (most likely due to a circular import)
```

**gencrypto.py**

```
import time
from cryptography.hazmat.primitives.asymmetric import dh


for i in [2048,3072,4096]:
    begin=time.time()
    params = dh.generate_parameters(
        generator=2,
        key_size=i,
    )
    end=time.time()
    print('took {}s for {} keysize'.format(int(end-begin), i))
```
Create py.typed
the changelog lists:

> cryptography now has PEP 484 type hints on nearly all of of its public APIs. Users can begin using them to type check their code with mypy.

but I'm still falling back to typeshed because this file is missing


Discussion:
Thanks, I've got a patch (soon to be a PR) and I think we'll do a point release for this.
You also need to add the file to package data, https://www.python.org/dev/peps/pep-0561/#packaging-type-information
> You also need to add the file to package data, https://www.python.org/dev/peps/pep-0561/#packaging-type-information

Isn't it already covered with include_package_data ?
> > You also need to add the file to package data, [python.org/dev/peps/pep-0561/#packaging-type-information](https://www.python.org/dev/peps/pep-0561/#packaging-type-information)
> 
> Isn't it already covered with include_package_data ?

Is ``include_package_data=True`` sufficient? I honestly don't know! Could you please check sdist and wheels?
You definitely have to add it to ``MANIFEST.in``:

```
flake run-test: commands[2] | check-manifest
lists of files in version control and sdist do not match!
missing from sdist:
  src/cryptography/py.typed
suggested MANIFEST.in rules:
  recursive-include src *.typed
```
> > > You also need to add the file to package data, [python.org/dev/peps/pep-0561/#packaging-type-information](https://www.python.org/dev/peps/pep-0561/#packaging-type-information)
> > 
> > 
> > Isn't it already covered with include_package_data ?
> 
> Is `include_package_data=True` sufficient? I honestly don't know! Could you please check sdist and wheels?

Yes, it's sufficient.

```
$ python3 setup.py bdist_wheel
$ unzip -l dist/cryptography-3.5.dev1-cp39-cp39-linux_x86_64.whl | grep py.typed
        0  02-09-2021 12:36   cryptography/py.typed
```

Resolving patch:
diff --git a/src/cryptography/__about__.py b/src/cryptography/__about__.py
--- a/src/cryptography/__about__.py
+++ b/src/cryptography/__about__.py
@@ -21,7 +21,7 @@
 )
 __uri__ = "https://github.com/pyca/cryptography"
 
-__version__ = "3.4.3"
+__version__ = "3.4.4"
 
 __author__ = "The Python Cryptographic Authority and individual contributors"
 __email__ = "cryptography-dev@python.org"
diff --git a/src/cryptography/hazmat/primitives/serialization/base.py b/src/cryptography/hazmat/primitives/serialization/base.py
--- a/src/cryptography/hazmat/primitives/serialization/base.py
+++ b/src/cryptography/hazmat/primitives/serialization/base.py
@@ -25,7 +25,7 @@ def load_pem_public_key(data: bytes, backend=None) -> _PUBLIC_KEY_TYPES:
     return backend.load_pem_public_key(data)
 
 
-def load_pem_parameters(data: bytes, backend=None) -> dh.DHParameters:
+def load_pem_parameters(data: bytes, backend=None) -> "dh.DHParameters":
     backend = _get_backend(backend)
     return backend.load_pem_parameters(data)
 
@@ -42,6 +42,6 @@ def load_der_public_key(data: bytes, backend=None) -> _PUBLIC_KEY_TYPES:
     return backend.load_der_public_key(data)
 
 
-def load_der_parameters(data: bytes, backend=None) -> dh.DHParameters:
+def load_der_parameters(data: bytes, backend=None) -> "dh.DHParameters":
     backend = _get_backend(backend)
     return backend.load_der_parameters(data)
diff --git a/vectors/cryptography_vectors/__about__.py b/vectors/cryptography_vectors/__about__.py
--- a/vectors/cryptography_vectors/__about__.py
+++ b/vectors/cryptography_vectors/__about__.py
@@ -18,7 +18,7 @@
 
 __uri__ = "https://github.com/pyca/cryptography"
 
-__version__ = "3.4.3"
+__version__ = "3.4.4"
 
 __author__ = "The Python Cryptographic Authority and individual contributors"
 __email__ = "cryptography-dev@python.org"


Test patch: