Fix docstring checker issues with PIL enums (#28450)

This commit is contained in:
Matt 2024-01-11 17:23:41 +00:00 committed by GitHub
parent 19e83d174c
commit 143451355c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -933,6 +933,10 @@ def replace_default_in_arg_description(description: str, default: Any) -> str:
except Exception:
# Otherwise there is a math operator so we add a code block.
str_default = f"`{current_default}`"
elif isinstance(default, enum.Enum) and default.name == current_default.split(".")[-1]:
# When the default is an Enum (this is often the case for PIL.Image.Resampling), and the docstring
# matches the enum name, keep the existing docstring rather than clobbering it with the enum value.
str_default = f"`{current_default}`"
if str_default is None:
str_default = stringify_default(default)