bunq / sdk_python

Python SDK for bunq API
MIT License
106 stars 25 forks source link

Python 3.4.2: ImportError: cannot import name 'context' (cyclic import?) #73

Closed jeroenmeulenaar closed 6 years ago

jeroenmeulenaar commented 6 years ago

Steps to reproduce:

What happens:


~ $ python3 test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from bunq.sdk import context
  File "/usr/local/lib/python3.4/dist-packages/bunq/sdk/context.py", line 9, in <module>
    from bunq.sdk.model.generated import endpoint
  File "/usr/local/lib/python3.4/dist-packages/bunq/sdk/model/generated/endpoint.py", line 3, in <module>
    from bunq.sdk import context
ImportError: cannot import name 'context'

It looks like a cyclic import (`context` importing `endpoint` and `endpoint` importing `context`), but I don't know why this is a problem for python 3.4.2.
jeroenmeulenaar commented 6 years ago

I now used pyenv to install 3.6.3 locally, and then this issue does not occur.

jeroenmeulenaar commented 6 years ago

And already in python version 3.5.5 this passes, but I can't find anything in the 3.5.5 release notes that would explain this.

OGKevin commented 6 years ago

Oh boy, is this related to #72 ? I think we need to bump the minimum required python version. The structure the SDK has no can indeed cause for circular dependencies. In early development we also suffered from this. Instead of importing the class directly we import the module. This seems to work fine and the latest version of python3 which was 3.6 at that time. We didn't test on lower versions of python3 🤦‍♂️.

jeroenmeulenaar commented 6 years ago

It's not directly related to #72, but they are both about issues running code on python version below python 3.6.

I found the change: it's in version 3.5.0. The release notes at https://docs.python.org/3.5/whatsnew/3.5.html write

Circular imports involving relative imports are now supported. (Contributed by Brett Cannon and Antoine Pitrou in bpo-17636.)

I guess this quite some work to fix (use only import foo instead of using from foo import bar). I'll just stick with pyenv; you can increase the minimum required python version to 3.5.