facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.28k stars 631 forks source link

Fix deprecated use/import of ABC from 'collections'. #546

Closed loozhengyuan closed 2 years ago

loozhengyuan commented 5 years ago

On facebook-business==3.3.2, running tests will show a DeprecationWarning like the following:

venv/lib/python3.7/site-packages/facebook_business/adobjects/abstractobject.py:29: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    class AbstractObject(collections.MutableMapping):

Based on PEP 596, Python 3.8 is due to be released on 21 Oct 2019. Given that this bug will break the SDK on Python 3.8, I've done the pull request to fix the aforementioned problem.

Please feel free to let me know if this edit is ok, thanks!

facebook-github-bot commented 5 years ago

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

facebook-github-bot commented 5 years ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

loozhengyuan commented 5 years ago

I've added a try/except block to handle backwards compatibility with Python 2.7 (although i'm not sure if Facebook intends to continue supporting 2.7. If the earlier revision is preferred, feel free to let me know as well. Otherwise, thanks!

loozhengyuan commented 5 years ago

Apologies, I later found out that not only the abstractobject.py file uses the wrong reference but also other files. Accordingly, I've made those edits and renamed the title to more accurately describe the issue this pull request attempts to fix.

Again, do me know if any further edits are required from my end, thanks!

zheplusplus commented 4 years ago

From six==1.13.0, six.moves.collection_abc is added so probably can use that instead of try/except.

from six.moves.collection_abc import Mapping, Sequence