-
Notifications
You must be signed in to change notification settings - Fork 5
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
Coerce BaseBGPRow
attribute values to expected types
#313
Conversation
🦙 MegaLinter status: ✅ SUCCESS
See detailed report in MegaLinter reports |
Test results 3 files 3 suites 1m 17s ⏱️ Results for commit 44e06b8. ♻️ This comment has been updated with latest results. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #313 +/- ##
=======================================
Coverage 97.31% 97.31%
=======================================
Files 64 64
Lines 7888 7895 +7
=======================================
+ Hits 7676 7683 +7
Misses 212 212 ☔ View full report in Codecov by Sentry. |
This requires Pydantic >= 2.7.0, as this is the first version that enables serialization warnings to be turned into errors/exceptions, which will trigger this test.
This fixes #312 by type-casting incoming attributes on BaseBGPRow. The expected Enum types have values designed to match the state strings from the BGP MIBs, so coercing the strings as early as possible should do.
While the code works, its always cleaner (and easier to type check) to refer to the Enum values rather than compare against string literals (which could be both redundant and incorrect).
0d0ff96
to
44e06b8
Compare
Quality Gate passedIssues Measures |
Scope and purpose
Fixes #312.
The issue could also have been fixed by ensuring the assigned types were correct to begin with, or by changing the type annotations of the dataclass to
str
and ensure the Pydantic model coerces the values instead, but this is my initial suggestion.Contributor Checklist
Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to Zino can be found in the
README.