File size: 998 Bytes
5673379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Patch gradio_client JSON-schema helpers (bool additionalProperties with pydantic v2)."""

from __future__ import annotations


def apply() -> None:
    try:
        import gradio_client.utils as gc_utils
    except ImportError:
        return

    if getattr(gc_utils, "_refdiffnet_patched", False):
        return

    _orig_get_type = gc_utils.get_type

    def get_type(schema):  # type: ignore[no-untyped-def]
        if not isinstance(schema, dict):
            return "Any"
        return _orig_get_type(schema)

    gc_utils.get_type = get_type  # type: ignore[assignment]

    _orig_json = gc_utils._json_schema_to_python_type

    def _json_schema_to_python_type(schema, defs):  # type: ignore[no-untyped-def]
        if not isinstance(schema, dict):
            return "Any"
        return _orig_json(schema, defs)

    gc_utils._json_schema_to_python_type = _json_schema_to_python_type  # type: ignore[assignment]
    gc_utils._refdiffnet_patched = True  # type: ignore[attr-defined]