Skip to content

Python 3.6 support #137

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

Closed
pawamoy opened this issue Aug 6, 2020 · 7 comments
Closed

Python 3.6 support #137

pawamoy opened this issue Aug 6, 2020 · 7 comments
Labels
✨ enhancement New feature or improvement
Milestone

Comments

@pawamoy
Copy link

pawamoy commented Aug 6, 2020

Is your feature request related to a problem? Please describe.
I was able to install Python 3.7 with pyenv, then openapi-python-client with pipx, but now I see that the generated clients are compatible with Python >=3.7 as well, because of this instruction at least:

from __future__ import annotations

(see https://stackoverflow.com/questions/52889746/cant-import-annotations-from-future/52890129)

If I understand correctly, this annotations import is used to avoid putting quotes around forward references (or avoid forward references themselves?) in models from_dict methods.

Describe the solution you'd like
Maybe openapi-python-client could provide a configuration option to tell what Python version is the target, and adapt its output to it. For Python 3.6, the from __future__ import annotations lines would be removed, and the from_dict methods of models would put quotes around their return type annotation.

Describe alternatives you've considered
I'm stuck with Python 3.6, at least for some time, so the only alternative I see is manually fixing the generated code, or writing a script to do it automatically 🙂

@pawamoy pawamoy added the ✨ enhancement New feature or improvement label Aug 6, 2020
@pawamoy
Copy link
Author

pawamoy commented Aug 6, 2020

And here are two sed commands to do just that:

sed -i '/from __future__ import annotations/d' */models/*.py
sed -r -i 's/(def from_dict\(d: Dict\[str, Any\]\) -> )(.+):$/\1"\2":/' */models/*.py

Make sure to adapt */models/*.py to fit your directory structure.

@dbanty
Copy link
Collaborator

dbanty commented Aug 6, 2020

@pawamoy is that the only piece of the generated clients that isn't compatible with 3.6? If so then we can just change the style to use quotes instead of __future__ for now. I thought data classes were added in 3.7 and we make pretty extensive use of them I think.

@pawamoy
Copy link
Author

pawamoy commented Aug 6, 2020

dataclasses can be installed as a dependency from PyPI, so this is solvable for Python 3.6. As for your question, I'm not sure yet, I've only executed "import time" code.

@dbanty
Copy link
Collaborator

dbanty commented Aug 6, 2020

Okay so we should also add that dependency then for 3.6 support.

@dbanty dbanty added this to the Python 3.6 Support milestone Aug 18, 2020
@dbanty dbanty modified the milestones: Python 3.6 Support, 0.6.0 Sep 6, 2020
dbanty added a commit that referenced this issue Sep 6, 2020
dbanty added a commit that referenced this issue Sep 7, 2020
@dbanty
Copy link
Collaborator

dbanty commented Sep 7, 2020

@pawamoy 0.6.0-alpha.3 (building now) should work with Python 3.6 (both the CLI and the generated clients). Please give it a spin when you get a chance and see if I missed anything.

@pawamoy
Copy link
Author

pawamoy commented Sep 7, 2020

@dbanty that's great, thanks! I'll give it a try.

@dbanty
Copy link
Collaborator

dbanty commented Sep 21, 2020

I haven't heard any complaints yet, and CI is now running 3.6 on every commit- so I'm pretty confident releasing 0.6.0 will finish this up. I'm going to close this issue to mark progress on 0.6.0 milestone, but definitely open a new one if you encounter any issues.

@dbanty dbanty closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants