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 equality check for custom classes #979

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

AryazE
Copy link

@AryazE AryazE commented Sep 8, 2024

Similar to This issue in rich, comparing types with == could be problematic. The canonical is would fix this problem.

@svlandeg svlandeg added the bug Something isn't working label Sep 9, 2024
@svlandeg svlandeg self-assigned this Sep 9, 2024
@svlandeg svlandeg changed the title Fixed issue with custom classes 🐛 Fix equality check for custom classes Sep 9, 2024
Copy link
Member

@svlandeg svlandeg left a 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.

@svlandeg svlandeg removed their assignment Sep 9, 2024
@@ -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():
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants