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 error with dataclasses #701

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aleph/vm/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
elif hasattr(o, "dict"): # Pydantic
return o.dict()
elif is_dataclass(o):
return dataclass_as_dict(o)
return dataclass_as_dict(o) # type: ignore

Check warning on line 78 in src/aleph/vm/utils/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/utils/__init__.py#L78

Added line #L78 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

What is the error and isn't there a more elegant way to solve the issue ?
# type: ignore looks a bit like "force-ignore-this".

Copy link
Collaborator

Choose a reason for hiding this comment

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

And shouldn't the return type be defined for this function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hoh That's explained in the PR description why I had to force ignore.

error was

src/aleph/vm/utils/__init__.py:78: error: No overload variant of "asdict" matches argument type "type[DataclassInstance]"  [call-overload]
src/aleph/vm/utils/__init__.py:78: note: Possible overload variants:
src/aleph/vm/utils/__init__.py:78: note:     def asdict(obj: DataclassInstance) -> dict[str, Any]
src/aleph/vm/utils/__init__.py:78: note:     def [_T] asdict(obj: DataclassInstance, *, dict_factory: Callable[[list[tuple[str, Any]]], _T]) -> _T
Found 1 error in 1 file (checked 71 source files)

DataclassInstance is not something that exist, so for me it looks like a mypy bug. But if you have another fix I would be happy to accept it.

@Psycojoker which function?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@olethanh github doesn't allow me to comment on any line but the exact function you are editing

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah it probably should but it's totally outside the scope of this PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ended up doing it here #704

Copy link
Member

Choose a reason for hiding this comment

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

I merged #704

else:
return str(o)

Expand Down
Loading