14
14
import functools
15
15
import inspect
16
16
import warnings
17
- from collections .abc import Generator
17
+ from collections .abc import Callable , Generator
18
18
from typing import (
19
19
Any ,
20
- Callable ,
21
20
ParamSpec ,
22
21
TypeVar ,
23
- Union ,
24
22
cast ,
25
23
)
26
24
@@ -42,7 +40,7 @@ class LangChainPendingDeprecationWarning(PendingDeprecationWarning):
42
40
43
41
44
42
# Last Any should be FieldInfoV1 but this leads to circular imports
45
- T = TypeVar ("T" , bound = Union [ type , Callable [..., Any ], Any ] )
43
+ T = TypeVar ("T" , bound = type | Callable [..., Any ] | Any )
46
44
47
45
48
46
def _validate_deprecation_params (
@@ -276,27 +274,25 @@ def finalize(wrapper: Callable[..., Any], new_doc: str) -> T: # noqa: ARG001
276
274
if not _obj_type :
277
275
_obj_type = "attribute"
278
276
wrapped = None
279
- _name = _name or cast ("Union[ type, Callable] " , obj .fget ).__qualname__
277
+ _name = _name or cast ("type | Callable" , obj .fget ).__qualname__
280
278
old_doc = obj .__doc__
281
279
282
280
class _DeprecatedProperty (property ):
283
281
"""A deprecated property."""
284
282
285
283
def __init__ (
286
284
self ,
287
- fget : Union [ Callable [[Any ], Any ], None ] = None ,
288
- fset : Union [ Callable [[Any , Any ], None ], None ] = None ,
289
- fdel : Union [ Callable [[Any ], None ], None ] = None ,
290
- doc : Union [ str , None ] = None ,
285
+ fget : Callable [[Any ], Any ] | None = None ,
286
+ fset : Callable [[Any , Any ], None ] | None = None ,
287
+ fdel : Callable [[Any ], None ] | None = None ,
288
+ doc : str | None = None ,
291
289
) -> None :
292
290
super ().__init__ (fget , fset , fdel , doc )
293
291
self .__orig_fget = fget
294
292
self .__orig_fset = fset
295
293
self .__orig_fdel = fdel
296
294
297
- def __get__ (
298
- self , instance : Any , owner : Union [type , None ] = None
299
- ) -> Any :
295
+ def __get__ (self , instance : Any , owner : type | None = None ) -> Any :
300
296
if instance is not None or owner is not None :
301
297
emit_warning ()
302
298
if self .fget is None :
@@ -315,7 +311,7 @@ def __delete__(self, instance: Any) -> None:
315
311
if self .fdel is not None :
316
312
self .fdel (instance )
317
313
318
- def __set_name__ (self , owner : Union [ type , None ] , set_name : str ) -> None :
314
+ def __set_name__ (self , owner : type | None , set_name : str ) -> None :
319
315
nonlocal _name
320
316
if _name == "<lambda>" :
321
317
_name = set_name
@@ -330,7 +326,7 @@ def finalize(wrapper: Callable[..., Any], new_doc: str) -> T: # noqa: ARG001
330
326
)
331
327
332
328
else :
333
- _name = _name or cast ("Union[ type, Callable] " , obj ).__qualname__
329
+ _name = _name or cast ("type | Callable" , obj ).__qualname__
334
330
if not _obj_type :
335
331
# edge case: when a function is within another function
336
332
# within a test, this will call it a "method" not a "function"
0 commit comments