Skip to content

Conversation

@hugovk
Copy link
Member

@hugovk hugovk commented Jan 8, 2023

Use single isinstance call for multiple types

For example, instead of:

isinstance(params, list) or isinstance(params, tuple)

Use:

isinstance(params, (list, tuple))

Docs: "If classinfo is a tuple of type objects (or recursively, other such tuples) or a Union Type of multiple types, return True if object is an instance of any of the types."

https://docs.python.org/3/library/functions.html#isinstance

Use key in mydict

For example, instead of:

key in TiffTags.TAGS_V2_GROUPS.keys()

Use:

key in TiffTags.TAGS_V2_GROUPS

Docs: "For mapping objects, this should consider the keys of the mapping rather than the values or the key-item pairs."

https://docs.python.org/3/reference/datamodel.html#object.__contains__

Use enumerate

For example, instead of:

frame_number = 0
for mpentry in mpinfo[0xB002]:
    ...
    frame_number += 1

Use:

for frame_number, mpentry in enumerate(mpinfo[0xB002]):
    ...

Docs: https://docs.python.org/3/library/functions.html#enumerate

@hugovk hugovk added the Cleanup label Jan 8, 2023
@radarhere radarhere merged commit 569b86b into python-pillow:main Jan 8, 2023
@hugovk hugovk deleted the simplify branch January 8, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants