-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
gh-102542 Refactor the mime audio module #102540
Conversation
e60185c
to
44c5f8c
Compare
_subtype = _what(_audiodata) | ||
if _subtype is None: | ||
raise TypeError('Could not find audio MIME subtype') | ||
_subtype = _subtype or _infer_subtype(_audiodata) |
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 changes the behavior if _subtype is '' (or any other non-None null value). Someone other than me needs to agree with 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.
That's correct. Falsey values other than None
such as: 0
, False
, ''
and empty collections will all fall back to the second or
operand: _infer_subtype(_audiodata)
.
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 personally prefer more explicit tests than just "falseiness" when a more explicit type is indicated. In this case _subtype=None
defaults to None to mean that this argument wasn't given.
@warsaw This PR mostly replaces the section you committed April '22. I believe that replacement logic is correct. Joseph, have you checked the coverage of the mime audio test? |
None of the tests execute this path as far as I could tell from putting a breakpoint in and running the tests. I convinced myself that the logic in |
e3f62eb
to
09cd7f1
Compare
Force pushed to correct a mistake in the commit message. |
That implies that we should perhaps first work on improving test coverage, before undertaking a risky refactoring of this module. ("Risky" only in the sense that all refactorings are risky if test coverage is low :) |
ac8e652
to
5b26332
Compare
You're right as usual;) Turns out adding the tests was easier than I first thought. Apologies for rebasing rather than merging, I'm still working on using that workflow @AlexWaygood |
Update: I was incorrect about this path not being tested - there are in fact tests for this, see: As such I've deleted the redundant ones. |
@terryjreedy could you have a re-review when you get a chance please. I think the minimum set of changes for this PR would be simply removing the unused |
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 have nothing to add, which was that I will not approve the change as this is outside my expertise.
Hia @AlexWaygood. Who I should request a review from on this? I have the feeling it may have slipped through people's todos! Cheers |
I've provided some additional thoughts on #102542 |
Closing as we've decided to leave the |
Refactor the MIME audio module, the mechanism for attempting to infer a subtype is currently quite verbose.
Notes:
fakefile
is not used in any of the functions it is passed to, hence it has been removed.hrd = data[:512]
) isn't necessary so has been removed.