Skip to content

Problem with python 3.7 and "async" as parameter name #558

Closed

Description

@amoralej

In python 3.7, async is a reserved keyword [1]. This module is using async as parameter name in different methods and it's failing with syntax errors like (excerpt):

File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/admissionregistration_api.py", line 120
async=params.get('async'),
^
SyntaxError: invalid syntax

byte-compiling /tmp/test/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/storage_v1alpha1_api.py to storage_v1alpha1_api.cpython-37.pyc
File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/storage_v1alpha1_api.py", line 132
async=params.get('async'),
^
SyntaxError: invalid syntax

byte-compiling /tmp/test/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/autoscaling_api.py to autoscaling_api.cpython-37.pyc
File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/autoscaling_api.py", line 120
async=params.get('async'),
^
SyntaxError: invalid syntax

Note that python 3.7 was released recently and some distros (as fedora) will be switching to it.

[1] https://docs.python.org/3.7/whatsnew/3.7.html#summary-release-highlights

Activity

  1. hroncok commented on Jun 28, 2018

    @hroncok

    Note that Fedora already is switching to Python 3.7.

  2. hroncok commented on Jun 28, 2018

    @hroncok

    It appears that async is part of the API which makes things hard to fix just by renaming. I have a decorator that might be useful for this (consider it Public Domain or CC0):

    from functools import wraps
    
    
    def deprecated_async(func):
        """A decorator, that let's us keep our old API, but deprecate it"""
        @wraps(func)
        def inner(*args, **kwargs):
            if 'async' in kwargs:
                if 'asynchronous' in kwargs:
                    raise ValueError('cannot use both async and asynchronous '
                                     'keyword arguments! the latter obsoletes the first.')
                warnings.warn('async keyword argumnt is deprecated, '
                              'use asynchronous instead', DeprecationWarning)
                kwargs['asynchronous'] = kwargs.pop('async')
            return func(*args, **kwargs)
        return inner
    
    
    @deprecated_async
    def awesome_func(foo, bar, asynchronous=False):
        """People can pass async or asynchronous"""
        ...
  3. tomplus commented on Jun 28, 2018

    @tomplus
    Member

    OMG, it looks like a breaking change, btw this part is generated by swagger-codegen.

    What does it mean "fedora is switching to p37" ?

  4. hroncok commented on Jun 28, 2018

    @hroncok

    What does it mean "fedora is switching to p37" ?

    https://fedoraproject.org/wiki/Changes/Python3.7

  5. tomplus commented on Jun 28, 2018

    @tomplus
    Member

    Thanks @hroncok , so Fedora 29 will use it. I though that latest version was switched or something ;)

  6. hroncok commented on Jun 28, 2018

    @hroncok

    But Fedora 29 already needs to use it at this point. From user perspective, this is something form the future, but from ours, it's the current one.

  7. Chekov2k commented on Jul 2, 2018

    @Chekov2k

    Since Homebrew updated Python to 3.7, my workaround for the Ansible OpenShift and Kubernetes integration was to run this little sed command in the kubernetes/openshift python module directory:

    cd /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kubernetes
    find . -name "*.py" | xargs sed -i '' s/async=para/async_=para/g
    cd /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openshift
    find . -name "*.py" | xargs sed -i '' s/async=para/async_=para/g
    

    Hope it helps someone until the issue is fixed properly

  8. jbiel commented on Jul 2, 2018

    @jbiel

    I ran into this after Homebrew updated Python to 3.7 this morning. @Chekov2k, how are you installing the Kubernetes python package to that directory? If I do a pip install it fails (due to this issue) and kubernetes isn't present in /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages.

  9. Chekov2k commented on Jul 2, 2018

    @Chekov2k

    @jbiel I just ran pip3 install kubernetes openshift with a clean install of python3 beforehand

  10. jbiel commented on Jul 3, 2018

    @jbiel

    Thanks @Chekov2k. I ended up using this:

    find /usr/local/lib/python3.7/site-packages/kubernetes/	 -name "*.py" | xargs sudo sed -i 's/async=/async_=/g'
    sudo sed -i 's/if not async:/if not async_:/' /usr/local/lib/python3.7/site-packages/kubernetes/client/api_client.py
    
  11. tomplus commented on Jul 8, 2018

    @tomplus
    Member

    I opened PR in swagger-codegen and added a simple workaround to gen repository. Next release should support Python 3.7.

    If you can't wait I suggest running

    find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/async=/async_req=/g' {} +
    find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/async bool/async_req bool/g' {} +
    find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i "s/'async'/'async_req'/g" {} +
    sed -i "s/if not async/if not async_req/g" "${OUTPUT_DIR}/client/api_client.py"
    

    where OUTPUT_DIR is the path to the library.

  12. roycaihw commented on Jul 27, 2018

    @roycaihw
    Member

    Closing as new releases have been generated using kubernetes-client/gen#67

  13. eastlondoner commented on Nov 5, 2018

    @eastlondoner

    @roycaihw could the re-generation be performed against the "old" releases?
    We're using GCP and the most recent stable K8s is 1.10 - which is not compatible with the 8.0 branch (it's compatible with the 6.0 branch, which doesn't work with python 3.7)

    PR here: #682

  14. added a commit that references this issue on Nov 6, 2019
  15. JccSanabria commented on Nov 9, 2019

    @JccSanabria

    Fixed up replacing just the inputs and regular attributes named async (not the _async) within the null.py file.

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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