File tree Expand file tree Collapse file tree 2 files changed +7
-19
lines changed
Expand file tree Collapse file tree 2 files changed +7
-19
lines changed Original file line number Diff line number Diff line change 1- from typing import TypedDict , Literal
1+ from typing import TypedDict , Literal , Protocol , runtime_checkable
22
33try :
44 from typing import NotRequired
1515 from typing_extensions import Doc
1616 except ImportError :
1717
18- class Doc :
18+ @runtime_checkable
19+ class Doc (Protocol ):
20+ documentation : str
21+
1922 def __init__ (self , documentation : str , / ):
2023 self .documentation = documentation
2124
Original file line number Diff line number Diff line change 1- from typing import Annotated , Any , Union
1+ from typing import Annotated , Union
22from .types import Doc
33
44
@@ -11,21 +11,6 @@ def is_support_uniontype():
1111 return True
1212
1313
14- def is_doc_meta (
15- obj : Annotated [Any , Doc ("The object to be checked." )],
16- ) -> Annotated [
17- bool , Doc ("True if the object is a documentation object, False otherwise." )
18- ]:
19- """
20- Check if the given object is a documentation object.
21-
22- Example:
23- >>> is_doc_meta(Doc("This is a documentation object"))
24- True
25- """
26- return getattr (obj , "__class__" ) == Doc and hasattr (obj , "documentation" )
27-
28-
2914def unwrap_doc (
3015 obj : Annotated [
3116 Union [Doc , str ], Doc (
@@ -41,6 +26,6 @@ def unwrap_doc(
4126 >>> unwrap_doc("This is a documentation string")
4227 'This is a documentation string'
4328 """
44- if is_doc_meta (obj ):
29+ if isinstance (obj , Doc ):
4530 return obj .documentation
4631 return str (obj )
You can’t perform that action at this time.
0 commit comments