Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions daras_ai_v2/paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import base64
from datetime import datetime
from time import time
from typing import Any, Literal, Mapping, Type, TypeVar
import typing
from typing import Any, ClassVar, List, Literal, Mapping, Type, TypeVar

import requests
from furl import furl
Expand All @@ -19,13 +18,13 @@


class PaypalResource(BaseModel):
_api_endpoint: str | None = None
_api_list_items_key: str | None = None
_api_endpoint: ClassVar[str | None] = None
_api_list_items_key: ClassVar[str | None] = None

id: str
create_time: datetime
update_time: datetime | None = None
links: typing.List
links: List
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Specify element type for links & avoid bare container

links: List loses the benefit of type checking and IntelliSense.
If PayPal always returns a list of mapping-like objects, annotate explicitly and consider optional default:

-    links: List
+    links: list[dict[str, Any]] = Field(default_factory=list)

This documents the shape, prevents ValidationError on missing key, and works seamlessly with Pydantic.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
links: List
- links: List
+ links: list[dict[str, Any]] = Field(default_factory=list)
🤖 Prompt for AI Agents
In daras_ai_v2/paypal.py at line 27, the variable 'links' is currently typed as
a bare List, which lacks specificity and type safety. Update the annotation to
specify the element type, such as List[Dict[str, Any]] or a more precise
Pydantic model if available, to reflect that 'links' contains mapping-like
objects. Additionally, consider providing a default value like an empty list to
avoid validation errors when the key is missing.


@classmethod
def list(cls: Type[T], list_all: bool = False, **params) -> list[T]:
Expand Down