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 placeholder deep copy #611

Merged
merged 4 commits into from
Sep 18, 2024
Merged

Conversation

AdrienVannson
Copy link
Contributor

@AdrienVannson AdrienVannson commented Sep 9, 2024

Summary

[EDIT] Fix #606

Checklist

  • If code changes were made then they have been tested.
  • This PR fixes an issue.


# We can't simply use object() here because pydantic automatically performs deep-copy of mutable default values
# See #606
PLACEHOLDER: Placeholder = Placeholder()
Copy link
Collaborator

@Gobot1234 Gobot1234 Sep 17, 2024

Choose a reason for hiding this comment

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

Suggested change
PLACEHOLDER: Placeholder = Placeholder()
PLACEHOLDER: Any = Placeholder()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure to understand, is there any reason for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's so it can be used anywhere and the type checker won't complain

Copy link
Contributor Author

@AdrienVannson AdrienVannson Sep 17, 2024

Choose a reason for hiding this comment

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

I think the type checker complains anyway: with mypy, your changes turns:
src/betterproto/__init__.py:224: error: Argument "default" to "field" has incompatible type "Placeholder | None"; expected "Field[Any]" [arg-type]
into
src/betterproto/__init__.py:224: error: Argument "default" to "field" has incompatible type "Any | None"; expected "Field[Any]" [arg-type]

It is coherent since if x has type T and y has type Any, then x = y should not be a valid operation. Wouldn't it be better to add # type: ignore on the lines where it is needed? I think the line 224 is the only one with this kind of error.

Copy link
Collaborator

@Gobot1234 Gobot1234 Sep 17, 2024

Choose a reason for hiding this comment

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

It should still be an Any, but the type ignore would be appreciated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the PR

@Gobot1234 Gobot1234 merged commit 1161803 into danielgtaylor:master Sep 18, 2024
19 checks passed
@AdrienVannson
Copy link
Contributor Author

Thanks!

@AdrienVannson AdrienVannson deleted the placeholder branch October 8, 2024 11:15
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.

PLACEHOLDER test sometimes fails when using pydantic
2 participants