hterik opened a new issue, #35823: URL: https://github.com/apache/airflow/issues/35823
### Description Right now the definition for `Context` is a `TypedDict` with `total=False`. https://github.com/apache/airflow/blob/910c95ea64b6e14bff842a031aaaae019c95f2ed/airflow/utils/context.pyi#L59 This means that all attributes not marked as [`Required`](https://docs.python.org/3/library/typing.html#typing.Required) can be absent. When using strict type checkers, they complain whenever one does a simple lookup like `context["params"] `that is always expected to exist. Pyright for example gives this error. > > Could not access item in TypedDict > "params" is not a required key in "Context", so access may result in runtime exceptionPylance[reportTypedDictNotRequiredAccess](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportTypedDictNotRequiredAccess) > (variable) context: Context To work around it one need to disable that checker or work around it with verbose handling of potential case of the attribute being absent, that should never be possible anyway. When looking at [the creation of context in taskinstance.py](https://github.com/apache/airflow/blob/910c95ea64b6e14bff842a031aaaae019c95f2ed/airflow/models/taskinstance.py#L711), it appears that most of the parameters are actually always present. I propose either * changing the `Context` `TypedDict` to have `total=True` and explicitly mark optional attributes as `NotRequired`. * Go through individual items and mark as `Required` ### Use case/motivation More reliable type checking. ### Related issues The addition of `total=False` was done in following PR and seems very unrelated to the change at hand there. Maybe it was a mistake? https://github.com/apache/airflow/pull/25749/files ### Are you willing to submit a PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
