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

[AIRFLOW-4227] Use python3-style type annotations. #5030

Closed
wants to merge 1 commit into from

Conversation

jmcarp
Copy link
Contributor

@jmcarp jmcarp commented Apr 2, 2019

Make sure you have checked all steps below.

Jira

  • My PR addresses the following Airflow Jira issues and references them in the PR title. For example, "[AIRFLOW-XXX] My Airflow PR"
    • https://issues.apache.org/jira/browse/AIRFLOW-4227
    • In case you are fixing a typo in the documentation you can prepend your commit with [AIRFLOW-XXX], code changes always need a Jira issue.
    • In case you are proposing a fundamental code change, you need to create an Airflow Improvement Proposal (AIP).
    • In case you are adding a dependency, check if the license complies with the ASF 3rd Party License Policy.

Description

  • Here are some details about my PR, including screenshots of any UI changes:

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
    • If you implement backwards incompatible changes, please leave a note in the Updating.md so we can assign it to a appropriate release

Code Quality

  • Passes flake8

@jmcarp jmcarp force-pushed the py3-type-annotations branch from de12238 to 00b663b Compare April 2, 2019 20:43
@@ -34,9 +34,9 @@ nose_args=$@
# Generate the `airflow` executable if needed
which airflow > /dev/null || python setup.py develop

echo "Initializing the DB"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accident?

@BasPH
Copy link
Contributor

BasPH commented Apr 2, 2019

Note: there is also this issue https://issues.apache.org/jira/browse/AIRFLOW-4205, part of a collection of issues on removing Python 2.

@jmcarp jmcarp force-pushed the py3-type-annotations branch from 00b663b to 26fbbd1 Compare April 3, 2019 00:22
@jmcarp
Copy link
Contributor Author

jmcarp commented Apr 3, 2019

Thanks @BasPH. Also, will we support python3.5 in the future? If so, we can use function annotations but not variable annotations.

@ashb
Copy link
Member

ashb commented Apr 3, 2019

We should probably support Python 3.5.2 which is what Ubuntu ships

@jmcarp jmcarp force-pushed the py3-type-annotations branch 2 times, most recently from 3741b1c to 59f0a90 Compare April 3, 2019 16:25
@jmcarp
Copy link
Contributor Author

jmcarp commented Apr 3, 2019

Thanks @ashb, I backed out variable annotations, and tests are passing on 3.5.x.

@jmcarp jmcarp force-pushed the py3-type-annotations branch from 59f0a90 to 532c6fa Compare April 10, 2019 03:49
@mik-laj
Copy link
Member

mik-laj commented Apr 10, 2019

What do you think about replacing collections.namedtuple with typing.NamedTuple?
https://docs.python.org/3/library/typing.html#typing.NamedTuple

@jmcarp jmcarp force-pushed the py3-type-annotations branch from 532c6fa to 2344d4c Compare April 10, 2019 20:30
@jmcarp
Copy link
Contributor Author

jmcarp commented Apr 10, 2019

Added some typed namedtuples. Since we're supporting python3.5, we can't use variable annotations, so I used the backwards-compatible syntax.

@Fokko
Copy link
Contributor

Fokko commented Apr 12, 2019

Can you rebase onto master?

@jmcarp jmcarp force-pushed the py3-type-annotations branch 2 times, most recently from a0fa71a to 942d40c Compare April 12, 2019 15:13
@jmcarp
Copy link
Contributor Author

jmcarp commented Apr 12, 2019

Looks like #5090 will fix the kubernetes tests here once it's ready.

@jmcarp jmcarp force-pushed the py3-type-annotations branch from 942d40c to 8471971 Compare April 20, 2019 19:39
@codecov-io
Copy link

codecov-io commented Apr 20, 2019

Codecov Report

Merging #5030 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5030      +/-   ##
==========================================
+ Coverage   78.67%   78.68%   +<.01%     
==========================================
  Files         470      470              
  Lines       30013    30020       +7     
==========================================
+ Hits        23613    23620       +7     
  Misses       6400     6400
Impacted Files Coverage Δ
airflow/operators/check_operator.py 92.64% <ø> (ø) ⬆️
airflow/models/baseoperator.py 93.92% <ø> (ø) ⬆️
airflow/models/variable.py 94.73% <ø> (ø) ⬆️
airflow/models/dag.py 93.51% <ø> (ø) ⬆️
airflow/operators/python_operator.py 95.8% <ø> (ø) ⬆️
.../kubernetes_request_factory/pod_request_factory.py 100% <100%> (ø) ⬆️
airflow/plugins_manager.py 86.79% <100%> (ø) ⬆️
airflow/models/dagbag.py 92.27% <100%> (ø) ⬆️
airflow/hooks/base_hook.py 92.15% <100%> (+0.49%) ⬆️
airflow/contrib/utils/gcp_field_sanitizer.py 91.17% <100%> (ø) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24b9c7c...192f3f9. Read the comment docs.

@jmcarp
Copy link
Contributor Author

jmcarp commented Apr 24, 2019

This should be ready to go now that #5090 is finished. cc @Fokko @kaxil

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @jmcarp

One more comment, apart from that LGTM. Makes the code much more readable.

@@ -99,7 +99,7 @@ class AirflowTestPlugin(AirflowPlugin):
flask_blueprints = [bp]
appbuilder_views = [v_appbuilder_package]
appbuilder_menu_items = [appbuilder_mitem]
stat_name_handler = staticmethod(stat_name_dummy_handler)
stat_name_handler = stat_name_dummy_handler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be because mypy was complaining about this otherwise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right @ashb, and mypy might be right to complain about staticmethod here, since stat_name_dummy_handler is a function and not a method, and already has the expected signature.

@feng-tao
Copy link
Member

feng-tao commented May 2, 2019

We could revisit this pr given we drop PY2?

@jmcarp jmcarp force-pushed the py3-type-annotations branch 2 times, most recently from 2ccd6aa to d34804e Compare May 5, 2019 14:24
@mik-laj
Copy link
Member

mik-laj commented May 6, 2019

02:01 $ grep -RE 'namedtuple\(' . --include \*.py
./tests/models/test_connection.py:ConnectionParts = namedtuple("ConnectionParts", ["conn_type", "login", "password", "host", "port", "schema"])
./tests/contrib/hooks/test_azure_container_instance_hook.py:        named_instance = namedtuple("InstanceView", instance_view.keys())(*instance_view.values())
./tests/contrib/hooks/test_azure_container_instance_hook.py:        named_instance = namedtuple("Events", instance_view.keys())(*instance_view.values())
./tests/contrib/hooks/test_wasb_hook.py:        Blob = namedtuple('Blob', ['name'])

It seems to me that all classes have not been changed. WDYT?

@jmcarp jmcarp force-pushed the py3-type-annotations branch from d34804e to dc0de57 Compare May 7, 2019 02:52
@jmcarp jmcarp force-pushed the py3-type-annotations branch 2 times, most recently from 736b616 to 7491815 Compare May 7, 2019 03:59
@jmcarp jmcarp force-pushed the py3-type-annotations branch from 7491815 to 192f3f9 Compare May 7, 2019 04:03
@jmcarp
Copy link
Contributor Author

jmcarp commented May 7, 2019

@mik-laj: I hadn't changed all the named tuples in tests, but now I've gone through and dropped all uses of collections.namedtuple. Thanks for checking.

@jmcarp
Copy link
Contributor Author

jmcarp commented Jun 3, 2019

Looks like this was reimplemented in #5327. Thanks @BasPH.

@jmcarp jmcarp closed this Jun 3, 2019
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

Successfully merging this pull request may close these issues.

8 participants