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 mypy errors caught in 1.11.2 #2808

Merged
merged 4 commits into from
Oct 12, 2024

Conversation

eapolinario
Copy link
Collaborator

Why are the changes needed?

mypy 1.11.2 catches new errors in flytekit:

❯ make lint
mypy flytekit/core
flytekit/core/type_engine.py:439: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
flytekit/core/type_engine.py:942: error: Argument 1 to "append" of "list" has incompatible type "tuple[Any, type[Any]]"; expected "tuple[Any,
GenericAlias]"  [arg-type]
flytekit/core/type_engine.py:951: error: Argument 1 to "append" of "list" has incompatible type "tuple[Any, type[Any]]"; expected "tuple[Any, GenericAlias]"  [arg-type]
flytekit/core/type_engine.py:2166: error: Argument 1 to "append" of "list" has incompatible type "tuple[Any, type[Any]]"; expected "tuple[Any, GenericAlias]"  [arg-type]
flytekit/core/python_auto_container.py:211: error: Need type annotation for "env" (hint: "env: dict[<type>, <type>] = ...")  [var-annotated]
flytekit/core/array_node_map_task.py:83: error: Need type annotation for "transformer"  [var-annotated]
Found 5 errors in 3 files (checked 48 source files)
make: *** [lint] Error 1

What changes were proposed in this pull request?

This PR fixes the new errors and opportunistically updates the version of ruff in precommit.

Notice that these types added to handle dataclasses only paper over the problem. We have some code that doesn't make any sense in the python type system, for example

) -> Type[dataclasses.dataclass()]: # type: ignore
. Ideally we should rip this all of this dataclass code out of flytekit.

How was this patch tested?

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
…mmit-hooks

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
def convert_marshmallow_json_schema_to_python_class(
schema: dict, schema_name: typing.Any
) -> Type[dataclasses.dataclass()]: # type: ignore
def convert_marshmallow_json_schema_to_python_class(schema: dict, schema_name: typing.Any) -> type:
Copy link
Collaborator Author

@eapolinario eapolinario Oct 11, 2024

Choose a reason for hiding this comment

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

python/cpython#102699 is a discussion about having a baseclass for dataclasses that could be used here instead of Type[dataclasses.dataclass()] which is invalid. Unfortunately that is just a proposal for now.

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.

Project coverage is 51.15%. Comparing base (cd8216a) to head (ef4e713).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
flytekit/core/type_engine.py 57.14% 3 Missing ⚠️
flytekit/core/array_node_map_task.py 50.00% 1 Missing ⚠️
flytekit/core/python_auto_container.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2808       +/-   ##
===========================================
- Coverage   76.82%   51.15%   -25.67%     
===========================================
  Files         196      302      +106     
  Lines       20301    25341     +5040     
  Branches     2610     2613        +3     
===========================================
- Hits        15596    12964     -2632     
- Misses       4004    12270     +8266     
+ Partials      701      107      -594     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wild-endeavor wild-endeavor merged commit 9e9dfdc into master Oct 12, 2024
104 of 106 checks passed
otarabai pushed a commit to otarabai/flytekit that referenced this pull request Oct 15, 2024
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
kumare3 pushed a commit that referenced this pull request Nov 8, 2024
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
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.

2 participants