Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: Add assertions to support
MetricWriter
#129base: ms_metric-writer-feature-branch
Are you sure you want to change the base?
feat: Add assertions to support
MetricWriter
#129Changes from all commits
677a463
beee947
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why not use
metric.header()
method?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.
Short answer: this is an artifact from the initial proof-of-concept for this class being implemented in https://github.com/msto/dataclass_io/ (i.e. only for dataclasses, not considering
Metric
)Long answer:
metric.header()
andinspect.get_fields()
have a lot oftype: ignore
s , and I'd rather use an implementation that's type-safe. (I have a mental TODO to clean up the volume oftype: ignores
in the repo, and I can leave a TODO that this function should be deprecated/merged intoinspect
once that happens.)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.
I think we should use it and fix it?
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.
just saying out loud this will not work if the
path
is a stream, like standard input, since it consumes the header.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.
I can add an assertion that the
path
is not/dev/stdin
. Are there other streams that are likely to be represented as aPath
?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.
Just streams I think
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.
Bump
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.
How do we feel about
_assert
functions raising errors other thanAssertionError
? I would probably be surprised by this.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.
I don't think
assert
should be used outside of unit tests, and I prefer to raise more specific exceptions.The Google style guide recommends/requires this as well:
The primary reason to avoid the use of assert statements is that they are intended for debugging and can be disabled.
Additionally, using
assert
makes it easy to fail to cover all branches of a program:I'm happy to rename the functions to something other than
assert_*
(I've usedvalidate_*
in the past), I was just trying to remain consistent with naming convention in the project.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.
This might be a good case for having a custom exception:
Then you would catch the exception with either
AssertionError
orValueError
.I do like having the explicit branch with
if
since code coverage analysis will identify it as a covered/uncovered branch depending on actual test coverage. With single-line statements (e.g.assert
), you don't get any branch information so it is easy to forget to test the exception paths.