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

Replace try-except block by if-else statement #192

Merged
merged 1 commit into from
Jun 23, 2024
Merged

Conversation

maxsos
Copy link
Contributor

@maxsos maxsos commented Jun 23, 2024

Description:

The current code uses a try-except block to handle a potential KeyError when looking up a color value in the COLORS_BY_VALUE and COLORS_BY_NAME dictionary:

Proposed Change:
Refactor the code to use an if-else conditional check instead of a try-except block. This change improves code readability and leverages a more predictable conditional flow:

Benefits:

  • Enhances code readability by removing the exception handling for a simple key lookup.
  • Clearly separates the logic for handling the presence and absence of the key in the dictionary.

Impact:
This change is expected to maintain the existing functionality while improving code clarity.

Please let me know if there are any specific tests or cases you would like me to address in this refactoring.

Thank you!

Copy link

codecov bot commented Jun 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@yezz123 yezz123 merged commit 6133cbe into pydantic:main Jun 23, 2024
19 checks passed
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