Decision Optimization

 View Only
Expand all | Collapse all

docplex.cp: Getting "DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working"

  • 1.  docplex.cp: Getting "DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working"

    Posted Mon July 20, 2020 09:46 AM
    When using docplext.cp with warnings enabled, I get this warning:

    venv/lib/python3.7/site-packages/docplex/cp/utils.py:30: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from collections import deque, Iterable # Python < 3.7

    Reproduction (note "-Wd" in the command-line to enable warnings):

    > python -Wd
    Python 3.7.4 (default, Jul 15 2019, 15:55:25)
    [GCC 4.7.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from docplex.cp.expression import integer_var

    It seems that there is deliberate code to handle this, but it isn't working as intended.
    This code in docplex/cp/utils.py (around line 30):

    try:
    from collections.abc import deque, Iterable # Python >= 3.7
    except:
    from collections import deque, Iterable # Python < 3.7

    Should be changed to:

    from collections import deque
    try:
    from collections.abc import Iterable # Python >= 3.7
    except:
    from collections import Iterable # Python < 3.7

    Thanks,
    Tomer

    ------------------------------
    Tomer Vromen
    ------------------------------

    #DecisionOptimization


  • 2.  RE: docplex.cp: Getting "DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working"

    Posted Tue July 21, 2020 10:12 AM
    Hello,

    Thanks for reporting this.
    Regards,

    Chris.

    ------------------------------
    Christiane Bracchi
    ------------------------------