Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
amoralej opened this issue Jun 28, 2018 · 14 comments
Closed

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

amoralej opened this issue Jun 28, 2018 · 14 comments

Comments

@amoralej
Copy link

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

@hroncok
Copy link

hroncok commented Jun 28, 2018

Note that Fedora already is switching to Python 3.7.

@hroncok
Copy link

hroncok commented Jun 28, 2018

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"""
    ...

@tomplus
Copy link
Member

tomplus commented Jun 28, 2018

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

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

@hroncok
Copy link

hroncok commented Jun 28, 2018

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

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

@tomplus
Copy link
Member

tomplus commented Jun 28, 2018

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

@hroncok
Copy link

hroncok commented Jun 28, 2018

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.

@Chekov2k
Copy link

Chekov2k commented Jul 2, 2018

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

@jbiel
Copy link

jbiel commented Jul 2, 2018

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.

@Chekov2k
Copy link

Chekov2k commented Jul 2, 2018

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

@jbiel
Copy link

jbiel commented Jul 3, 2018

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

@tomplus
Copy link
Member

tomplus commented Jul 8, 2018

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.

@roycaihw
Copy link
Member

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

@eastlondoner
Copy link

eastlondoner commented Nov 5, 2018

@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

noris-bot pushed a commit to noris-network/koris that referenced this issue Nov 6, 2019
@JccSanabria
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants