Skip to content

Commit a791703

Browse files
fix: update variable names to avoid redefinition in unstructured_parser.py
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent 5646f38 commit a791703

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

airbyte_cdk/sources/file_based/file_types/unstructured_parser.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
import mimetypes
1414
import nltk
1515
import requests
16-
from unstructured.file_utils.filetype import (
17-
FileType,
18-
detect_filetype,
19-
)
16+
from unstructured.file_utils.filetype import FileType, detect_filetype
2017

2118
from airbyte_cdk.models import FailureType
2219
from airbyte_cdk.sources.file_based.config.file_based_stream_config import FileBasedStreamConfig
@@ -334,10 +331,10 @@ def _read_file_remotely(
334331
data = self._params_to_dict(format.parameters, strategy)
335332

336333
mime_type = mimetypes.guess_type(f"file.{filetype.name.lower()}")[0] if filetype else "application/octet-stream"
337-
file_data = {"files": ("filename", file_handle, mime_type)}
334+
files = {"files": ("filename", file_handle, mime_type)}
338335

339336
response = requests.post(
340-
f"{format.api_url}/general/v0/general", headers=headers, data=data, files=file_data
337+
f"{format.api_url}/general/v0/general", headers=headers, data=data, files=files
341338
)
342339

343340
if response.status_code == 422:
@@ -416,17 +413,17 @@ def _get_filetype(self, file: IOBase, remote_file: RemoteFile) -> Optional[FileT
416413
# detect_filetype is either using the file name or file content
417414
# if possible, try to leverage the file name to detect the file type
418415
# if the file name is not available, use the file content
419-
file_type: FileType | None = None
416+
detected_type: FileType | None = None
420417
try:
421-
file_type = detect_filetype(
418+
detected_type = detect_filetype(
422419
filename=remote_file.uri,
423420
)
424421
except Exception:
425422
# Path doesn't exist locally. Try something else...
426423
pass
427424

428-
if file_type and file_type != FileType.UNK:
429-
return file_type
425+
if detected_type and detected_type != FileType.UNK:
426+
return detected_type
430427

431428
type_based_on_content = detect_filetype(file=file)
432429
file.seek(0) # detect_filetype is reading to read the file content, so we need to reset

0 commit comments

Comments
 (0)