Skip to content

Commit 1480e6a

Browse files
committed
fixed python 3.9 tests
Signed-off-by: aritroCoder <ogcodinggod@gmail.com>
1 parent 6974241 commit 1480e6a

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

tests/unit/test_cache.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,12 @@ class Person(BaseModel):
260260
def test_schema_with_many_fields(self) -> None:
261261
"""Verify key generation handles schemas with many fields."""
262262
# Arrange
263-
# Create schema with 50+ fields using proper Pydantic field definition
264-
from pydantic import Field
263+
# Create schema with 50+ fields using create_model to avoid polluting BaseModel
264+
from pydantic import create_model
265265

266-
fields_dict = {f"field_{i}": (str, Field(default="")) for i in range(60)}
267-
268-
class LargeSchema(BaseModel):
269-
pass
270-
271-
# Dynamically add fields to the model
272-
for field_name, field_type in fields_dict.items():
273-
LargeSchema.__annotations__[field_name] = field_type[0]
274-
setattr(LargeSchema, field_name, field_type[1])
275-
276-
# Rebuild model to process the new fields
277-
LargeSchema.model_rebuild()
266+
# Create a dictionary suitable for create_model
267+
fields_dict = {f"field_{i}": (str, ...) for i in range(60)}
268+
LargeSchema = create_model("LargeSchema", **fields_dict) # type: ignore # noqa: N806
278269

279270
prompt = "Generate data"
280271
model = "llama-3.1-8b-instant"

0 commit comments

Comments
 (0)