bunq / sdk_python

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

cannot import name 'ApiContext' from 'bunq.sdk.context' #132

Closed echoes341 closed 4 years ago

echoes341 commented 4 years ago

I cannot import ApiContext. I'm not expert on Python, so there's no much I can do to help unfortunately.

Steps to reproduce:

This is easy to reproduce with docker

$ docker run --rm -it python bash

On the interactive shell:

root@2b615a0e8b39:/# pip install bunq_sdk
...
root@2b615a0e8b39:/# mkdir test
root@2b615a0e8b39:/# cd test
root@2b615a0e8b39:/test# cat > test.py
from bunq.sdk.context import ApiContext
print('Hello')
root@2b615a0e8b39:/test# python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from bunq.sdk.context import ApiContext
ImportError: cannot import name 'ApiContext' from 'bunq.sdk.context' (/usr/local/lib/python3.8/
site-packages/bunq/sdk/context/__init__.py)

What should happen:

  1. It should import the module

What happens:

  1. It fails returning:
    ImportError: cannot import name 'ApiContext' from 'bunq.sdk.context' (/usr/local/lib/python3.8/
    site-packages/bunq/sdk/context/__init__.py)

SDK version and environment

Response id

Extra info:

MarcellaJP commented 4 years ago

We had the same issue after upgrading to the latest version and it's because there are several breaking changes in the new version... Change the import to:

from bunq.sdk.context.bunq_context import ApiContext

In case it might help, other breaking changes that I have encountered are:

And whereas before you could initialize the ApiContext with something as

Good luck!

echoes341 commented 4 years ago

Thank you @MarcellaJP !

tlrh314 commented 4 years ago

The changelog is restored in https://github.com/bunq/sdk_python/commit/9d7dbc97304e12b73e8e06776f560dc45e61f4ac, indicating that major refactoring was merged in https://github.com/bunq/sdk_python/pull/117.

@angelomelonas It would be neat if a word of caution would be added to the README and in the description of the 1.13.1 release itself that updating from 1.10.16 to 1.13.1 requires users of this package to implement the fixes as indicated by @MarcellaJP.

angelomelonas commented 4 years ago

Hi everyone. I apologise for the very late response to this issue.

In order to improve the readability and maintainability of the Python SDK, we performed this refactor. Instead of having functions in very large files, we extracted them into separate files (to match the directory and file structure of the other SDKs). In the process, we also added type hints and other general improvements.

Unfortunately, this leads to the breaking changes @echoes341 and @MarcellaJP mention above. We definitely should have mentioned them in the CHANGELOG.

We have created a new issue which mentions the breaking changes. We will create a new PR that mentions the breaking changes (and the issue) in the CHANGELOG.

tlrh314 commented 4 years ago

Awesome, thanks @angelomelonas 🔥 🤩