-
Notifications
You must be signed in to change notification settings - Fork 6
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
Initial guidance on using type annotations #49
base: main
Are you sure you want to change the base?
Conversation
|
||
* Do not use `from __future__ import annotations` since it is not compatible with Python 3.6 | ||
* For importing typing see: http://google.github.io/styleguide/pyguide.html#31912-imports-for-typing | ||
* Define type annotations as strings so `'int'` instead of `int`. This prevents having issues where types are self referencing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's worth adding all these characters for the small number of classes that reference themselves. Let's just do this on the rare cases it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So http://google.github.io/styleguide/pyguide.html#31912-imports-for-typing states:
Conditionally imported types need to be referenced as strings, to be forward compatible with Python 3.6 where the annotation expressions are actually evaluated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend us sticking with strings for now to be consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about instead we wait until we've dropped support for python 3.6, as this string ugliness isn't required in Python 3.7+ https://www.python.org/dev/peps/pep-0563/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So type annotations will remain somewhat "ugly" with Python 3.7 and later as well, but we can postpone adopting them once we are able to drop 3.6 support.
No description provided.