-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
Context class handles deprecation #19886
Context class handles deprecation #19886
Conversation
I wonder if this would help #14396. We can make |
@uranusjr -> FYI MyPy is disabled temporarily, in case you have not noticed. But I think I will add it back in non-failure mode, just to incrementally fix the remaining problems. |
Bad news, you can’t override anything in |
47b852b
to
f977afd
Compare
How about we use dynamic attributes with set/get_attr and stub files from PEP 484 ? https://www.python.org/dev/peps/pep-0484/#stub-files - I think major IDEs already nicely support them. This way we would not have to unnecesarily complicate the implementation. That very nicely fits my "requirements" for less-nebulous context #14396 (comment) |
If we use stub files, we can continue using a dict-like class (i.e. don’t need dynamic setattr/getattr) and just “pretend” the class is actually a TypedDict in |
As mentioned in #14396, I have a chunk of that one already done in my working branch. I wanted to try to polish it a bit more before sending in a PR; it currently passes local CI and supports type hinting, but not auto-completing. As you pointed out, TypedDict won't let you override anything. I had hoped to use @Property tags to allow auto-completing, but no dice there. I'll look into stub files, I'm not familiar with using those yet. |
If I manage to get the tests pass for the Context class change (trying to do that right now), I’ll add a stub file tomorrow as an example how this would work that you can test out. |
Did some reading and checked out |
I pushed a commit with a One nice thing about Context being (faked as) a TypedDict is, all existing |
Cool! |
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. |
4ca30f9
to
b953fb9
Compare
Very cool. That was definitely a better solution than what I was doing, I'll drop mine and pick up something else to work on. For my own benefit, is there a particular reason why you dropped the context module in |
Not really. I actually thought a while trying to decide, but eventually just picked one arbitrarily since it doesn't really matter either way. |
(cherry picked from commit caaf6dc)
Fix #19716, close #19734.
Fortunately (?) we don’t really set up Mypy with enough information to catch typing errors this introduces to
def execute(self, context: Dict):
. I still intend to fix those eventually, but this helps producing a cleaner diff to run against CI.Now that we have a class (and a separate module), I also want to move more logic from the giant
TaskInstance.get_template_context()
(currently ~250 lines).