Skip to content

Circular import error (again) in 3.4.3 #5794

@mat-gas

Description

@mat-gas

Opening a new issue as the old one (#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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions