-
-
Notifications
You must be signed in to change notification settings - Fork 671
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 equality check for custom classes #979
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Changing the check from equality to identity check seems correct to me, also considering that the official Python documentation on inspect.Parameter
also includes this snippet:
if param.default is param.empty
The test you included fails on master
and succeeds on this PR. I only added 2 more lines to ensure 100% code coverage.
tests/test_annotated.py
Outdated
@@ -76,3 +76,35 @@ def cmd(force: Annotated[bool, typer.Option("--force")] = False): | |||
result = runner.invoke(app, ["--force"]) | |||
assert result.exit_code == 0, result.output | |||
assert "Forcing operation" in result.output | |||
|
|||
|
|||
def test_default_with_class_with_custom_eq(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiangolo: we might want this test in a different location in the test suite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I just moved it to another file. Not sure about the name, but it will work for now. 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to This issue in
rich
, comparing types with==
could be problematic. The canonicalis
would fix this problem.