Slightly simplify imgformat retrieval #201
Loading…
Reference in a new issue
No description provided.
Delete branch "mara0004/img2pdf:imgformat"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
No need for a loop here - we can access the enum like a dictionary.
nit: slightly simplify imgformat retrievalto Slightly simplify imgformat retrievalYes, if your python version is recent enough. Is there an objective reason to change this?
In the python docs, Enum
__getitem__
has no versionadded note, so I don't think this is a recent addition? Moreover, I believe you're already using this syntax in other places of img2pdf, where dotted access would not work (e.g.Rotation["0"]
,Colorspace["CMYK;I"]
.Well, not that it matters much here, but the time complexity of a dict lookup should be O(1) whereas looping over the members is O(length). Also, the current loop seems to be lacking a
break
. So this is just a bit cleaner.Come to think of it,
getattr(ImageFormat, imgdata.format, ImageFormat.other)
would be even simpler than subscription in try/except.getattr()
2b563c0982I updated the code to
getattr(...)
as drafted above. It's a one-liner now.Thank you! Could you squash both commits into one?
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.