python-pydantic-v1: Keep trailing commas for enum validation tuples (#19985)

* python-pydantic-v1: Keep trailing commas for tuples when enum has just single member

* Update samples

* Add test for single member enums

* Refactor test name
This commit is contained in:
Chirag Jain
2024-11-02 12:56:19 +05:30
committed by GitHub
parent 66c7b2f8cc
commit 67af02ccc8
35 changed files with 188 additions and 54 deletions

View File

@@ -44,7 +44,7 @@ class DefaultValue(BaseModel):
return value
for i in value:
if i not in ('success', 'failure', 'unclassified'):
if i not in ('success', 'failure', 'unclassified',):
raise ValueError("each list item must be one of ('success', 'failure', 'unclassified')")
return value

View File

@@ -42,7 +42,7 @@ class Pet(BaseModel):
if value is None:
return value
if value not in ('available', 'pending', 'sold'):
if value not in ('available', 'pending', 'sold',):
raise ValueError("must be one of enum values ('available', 'pending', 'sold')")
return value

View File

@@ -37,7 +37,7 @@ class Query(BaseModel):
return value
for i in value:
if i not in ('SUCCESS', 'FAILURE', 'SKIPPED'):
if i not in ('SUCCESS', 'FAILURE', 'SKIPPED',):
raise ValueError("each list item must be one of ('SUCCESS', 'FAILURE', 'SKIPPED')")
return value