Skip to content

Commit 2116962

Browse files
format check
1 parent 25bfa96 commit 2116962

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

stagehand/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,27 +416,27 @@ def transform_type(annotation, path):
416416
def is_url_type(annotation):
417417
"""
418418
Checks if a type annotation is a URL type (directly or nested in a container).
419-
419+
420420
This function is part of the URL transformation system that handles Pydantic models
421421
with URL fields during extraction operations. When extracting data from web pages,
422422
URLs are represented as numeric IDs in the accessibility tree, so we need to:
423-
423+
424424
1. Identify which fields in Pydantic models are URL types
425425
2. Transform those fields to numeric types during extraction
426426
3. Convert the numeric IDs back to actual URLs in the final result
427-
427+
428428
Pydantic V2 Compatibility Notes:
429429
--------------------------------
430430
Modern Pydantic versions (V2+) can create complex type annotations that include
431-
subscripted generics (e.g., typing.Annotated[...] with constraints). These
431+
subscripted generics (e.g., typing.Annotated[...] with constraints). These
432432
subscripted generics cannot be used directly with Python's issubclass() function,
433-
which raises TypeError: "Subscripted generics cannot be used with class and
433+
which raises TypeError: "Subscripted generics cannot be used with class and
434434
instance checks".
435-
435+
436436
To handle this, we use a try-catch approach when checking for URL types, allowing
437437
the function to gracefully handle both simple type annotations and complex
438438
subscripted generics that Pydantic V2 may generate.
439-
439+
440440
URL Type Detection Strategy:
441441
---------------------------
442442
1. Direct URL types: AnyUrl, HttpUrl from Pydantic
@@ -450,7 +450,7 @@ def is_url_type(annotation):
450450
Returns:
451451
bool: True if the annotation represents a URL type (directly or nested),
452452
False otherwise.
453-
453+
454454
Examples:
455455
>>> is_url_type(AnyUrl)
456456
True

0 commit comments

Comments
 (0)