-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdataclass_response.py
More file actions
45 lines (36 loc) · 1.07 KB
/
dataclass_response.py
File metadata and controls
45 lines (36 loc) · 1.07 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Optional, TypedDict, Union
from unstructured_ingest.data_types.file_data import BatchFileData, FileData
class SampleFunctionResponse(TypedDict):
response: dict[str, Any]
@dataclass
class SampleFunctionInput:
name: str
value: float
@dataclass
class SampleFunctionWithPathResponse:
t: str
exists: bool
resolved: str
b: str
c: int
p: bool
def sample_function_with_path(
file_data: Union[FileData, BatchFileData], b: str, c: int, a: Optional[Path] = None
) -> SampleFunctionWithPathResponse:
s: list[Any] = [type(a).__name__, f"[exists: {a.exists()}]", a.resolve()] if a else []
s.extend([b, c])
resp = {
"t": type(a).__name__,
"exists": a.exists(),
"resolved": a.resolve(),
"b": b,
"c": c,
"p": (
False
if isinstance(file_data, BatchFileData)
else file_data.source_identifiers.relative_path is not None
),
}
return SampleFunctionWithPathResponse(**resp)