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

Fix last remaining MyPy errors #21020

Merged
merged 1 commit into from
Jan 24, 2022
Merged

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Jan 21, 2022

Closes: #19891


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

@boring-cyborg boring-cyborg bot added area:API Airflow's REST/HTTP API area:dev-tools area:providers area:Scheduler including HA (high availability) scheduler provider:amazon-aws AWS/Amazon - related issues provider:google Google (including GCP) related issues labels Jan 21, 2022
@potiuk
Copy link
Member Author

potiuk commented Jan 21, 2022

Seems like this one will also be a collaborative effort eventually, There are a few errors around "airflow.models.decorators" package which I am not entirely sure why they are there and whether I made the right fix.

The one remaining - after I think I solved all other is

airflow/models/dag.py:2118: error: Argument 1 to "partial" has incompatible
type "_TaskDecoratorFactory"; expected "Callable[..., Any]"  [arg-type]
    ...return cast("TaskDecoratorFactory", functools.partial(task, dag=self))
                                                             ^
airflow/models/dag.py:2118: note: "_TaskDecoratorFactory.__call__" has type "staticmethod"
Found 1 error in 1 file (checked 2704 source files)

ERROR: The previous step completed with error. Please take a look at output above 

But I am not sure if the fixes are added are good. Seems like mypy sometimes uses the stub and sometimes not and I have no idea why.

@potiuk
Copy link
Member Author

potiuk commented Jan 21, 2022

Any help appreciated @uranusjr @ashb :D

@uranusjr
Copy link
Member

The naming and structuring of airflow/decorators/__init__.py is a small disaster. Let’s leave it out of this PR, I can fix them separately and perhaps try to improve the situation a bit.

@potiuk
Copy link
Member Author

potiuk commented Jan 21, 2022

Ehh. so you will be the last one :)

@potiuk
Copy link
Member Author

potiuk commented Jan 21, 2022

@uranusjr - removed it. Let's do it this way - since I also want to re-enable mypy and we should wait a few days with some "older PRs" to get "no-rebase" warning, I will continue rebasing that one until it gets "green". So feel free to unentangle the "decorators" disaster in the meantime

@potiuk potiuk force-pushed the fix-last-mypy-errors branch 2 times, most recently from 4cf9fbc to 25e2a1e Compare January 21, 2022 19:15

assert isinstance(data, list)
assert len(data) == 0
with pytest.raises(ValueError):
Copy link
Member Author

@potiuk potiuk Jan 21, 2022

Choose a reason for hiding this comment

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

I have a slight doubt about this one. This is "technically" breaking change with the experimental API, but one that should be very welcomed by any user. So I am tempted to leave it like that (I would treat it as a bugfix).

Copy link
Member

Choose a reason for hiding this comment

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

What bit throws the value error here? (It's not clear to from just looking at the code)

Oh, that state=dummy results in a ValueError -- wouldn't that result in a 500 returned, when instead it should be a 400?

@potiuk
Copy link
Member Author

potiuk commented Jan 21, 2022

All right @uranusjr . Decorators are all yours:

No need to rebuild the image: none of the important files changed

airflow/models/dag.py:91: error: Module "airflow.decorators" has no attribute
"TaskDecoratorFactory"; maybe "_TaskDecoratorFactory" or "TaskDecorator"? 
[attr-defined]
        from airflow.decorators import TaskDecoratorFactory
        ^
airflow/models/dag.py:2118: error: Argument 1 to "partial" has incompatible
type "_TaskDecoratorFactory"; expected "Callable[..., Any]"  [arg-type]
    ...return cast("TaskDecoratorFactory", functools.partial(task, dag=self))
                                                             ^
airflow/models/dag.py:2118: note: "_TaskDecoratorFactory.__call__" has type "staticmethod"
Found 2 errors in 1 file (checked 2704 source files)

ERROR: The previous step completed with error. Please take a look at output above 


No need to rebuild the image: none of the important files changed

airflow/example_dags/tutorial_taskflow_api_etl.py:25: error: Module
"airflow.decorators" has no attribute "dag"  [attr-defined]
    from airflow.decorators import dag, task
    ^
Found 1 error in 1 file (checked 403 source files)

ERROR: The previous step completed with error. Please take a look at output above 

@potiuk
Copy link
Member Author

potiuk commented Jan 24, 2022

Right - rebased and fixed last two errors: @uranusjr @ashb - I fixed two small thing (not even errors but inconsistencies and MyPy complaints in the new Operator Interface - I am not sure if adding "owner" to interface is a good idea - I think think we do not need to add dag though (as get_dag() shoudl return it anyway):

The errors were:

airflow/models/base.py:67: error: "Operator" has no attribute "dag" 
[attr-defined]
                return self.dag.dag_id
                       ^
airflow/models/base.py:68: error: "Operator" has no attribute "owner" 
[attr-defined]
            return f"adhoc_{self.owner}"


@potiuk potiuk mentioned this pull request Jan 24, 2022
10 tasks
none_depends_on_past = all(not t.task.depends_on_past for t in unfinished_tasks)
none_task_concurrency = all(t.task.max_active_tis_per_dag is None for t in unfinished_tasks)
none_depends_on_past = all(
not t.task.depends_on_past for t in unfinished_tasks # type: ignore[has-type]
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised this needs type ignoring.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, t.task could be None as far as typing is concenred?

@github-actions
Copy link

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Jan 24, 2022
@potiuk potiuk merged commit 9ed9b51 into apache:main Jan 24, 2022
@potiuk potiuk deleted the fix-last-mypy-errors branch January 24, 2022 21:39
@uranusjr
Copy link
Member

uranusjr commented Jan 25, 2022

Those two are easy, use get_dag instead. Oh, those are already fixed in #20945 (my myself lol), so we should be good now!

@jedcunningham jedcunningham added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Mar 1, 2022
@potiuk potiuk restored the fix-last-mypy-errors branch April 26, 2022 20:48
@potiuk potiuk deleted the fix-last-mypy-errors branch July 29, 2022 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API area:dev-tools area:providers area:Scheduler including HA (high availability) scheduler changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) full tests needed We need to run full set of tests for this PR to merge provider:amazon-aws AWS/Amazon - related issues provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-enable MyPy
4 participants