GeezerVison is showing github.com — Refactor the MIMEAudio module · Issue #102542 · python/cpython
Refactor the MIMEAudio module #102542
Description
We can remove almost half of this file without losing any expressiveness and marginally improve performance at the same time.
Linked PRs
Activity
warsaw commented on Jul 3, 2023
@JosephSBoyle - thanks for your contributions. I'm commenting here rather than on the PR (although I did add some feedback over there). Please also notice that Lib/email/mime/image.py uses a similar "rules" based mechanism to infer the image/* subtype when not provided.
One reason I went with this in my rewrite was so that we could easily extend the list of subtypes that we could recognize. Just add another @rule and you're done. While rule() isn't explicitly exposed publicly in either module, one could conceivably extend the list of subtypes in 3rd party code by doing something like:
from email.mime.audio import rule
@rule
def _my_image_type(h):
if h[:5] == 'FLUFL':
return 'flufl'
I wouldn't want to lose that implicit extensibility unless there's a good reason to. I'm not sure module size or "marginally improved performance" are compelling enough. Can you provide some performance numbers? Even if they were mind-blowingly better, I'm not sure this is performance critical code.
JosephSBoyle commented on Jul 4, 2023
ContributorAuthor
More actions
Hi @warsaw, thanks for taking a look at the PR.
I wouldn't want to lose that implicit extensibility unless there's a good reason to
Fair enough, I'm sure that someone is registering their own rules so it makes sense to keep that functionality 😄
Would you accept a new, smaller PR to remove the unnecessary header slicing and unused fakefile instance?
warsaw commented on Jul 4, 2023
Would you accept a new, smaller PR to remove the unnecessary header slicing and unused fakefile instance?
I would! Yeah, there's no reason any more to slice the data and it makes sense for audio.py and image.py to have a similar implementation (but not the same implementation because they have different _rules).
JosephSBoyle commented on Jul 4, 2023
ContributorAuthor
More actions
JosephSBoyle commented on Jul 6, 2023
ContributorAuthor
More actions
Metadata
Metadata
Development
No branches or pull requestsIssue actions