Skip to content

Commit

Permalink
rfctr: prepare for fix to raises on file-like-object with name not a …
Browse files Browse the repository at this point in the history
…path to a file (#2617)

**Summary**
Improve typing and other mechanical refactoring in preparation for fix
to issue 2308.
  • Loading branch information
scanny committed Mar 6, 2024
1 parent 79552ff commit b59e4b6
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 101 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.12.6-dev5
## 0.12.6-dev6

### Enhancements

Expand Down
5 changes: 3 additions & 2 deletions test_unstructured/partition/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from PIL import Image
from unstructured_inference.inference import layout
from unstructured_inference.inference.elements import TextRegion
from unstructured_inference.inference.layout import DocumentLayout, LayoutElement, PageLayout
from unstructured_inference.inference.layout import DocumentLayout, PageLayout
from unstructured_inference.inference.layoutelement import LayoutElement

from unstructured.documents.coordinates import PixelSpace
from unstructured.documents.elements import (
Expand All @@ -28,7 +29,7 @@


class MockPageLayout(layout.PageLayout):
def __init__(self, number: int, image: Image):
def __init__(self, number: int, image: Image.Image):
self.number = number
self.image = image

Expand Down
12 changes: 11 additions & 1 deletion typings/pptx/table.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
class Table: ...
class Table:
@property
def rows(self) -> tuple[_Row]: ...

class _Row:
@property
def cells(self) -> tuple[_Cell]: ...

class _Cell:
@property
def text(self) -> str: ...
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.12.6-dev5" # pragma: no cover
__version__ = "0.12.6-dev6" # pragma: no cover
2 changes: 1 addition & 1 deletion unstructured/documents/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ class Footer(Text):
category = "Footer"


TYPE_TO_TEXT_ELEMENT_MAP: Dict[str, Any] = {
TYPE_TO_TEXT_ELEMENT_MAP: Dict[str, type[Text]] = {
ElementType.TITLE: Title,
ElementType.SECTION_HEADER: Title,
ElementType.HEADLINE: Title,
Expand Down
22 changes: 6 additions & 16 deletions unstructured/file_utils/filetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from unstructured.file_utils.encoding import detect_file_encoding, format_encoding_str
from unstructured.nlp.patterns import LIST_OF_DICTS_PATTERN
from unstructured.partition.common import (
_add_element_metadata,
_remove_element_metadata,
add_element_metadata,
exactly_one,
remove_element_metadata,
set_element_hierarchy,
)

Expand Down Expand Up @@ -602,16 +602,11 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> List[Element]:
# NOTE(robinson) - Attached files have already run through this logic
# in their own partitioning function
if element.metadata.attached_to_filename is None:
_add_element_metadata(
element,
**metadata_kwargs, # type: ignore
)
add_element_metadata(element, **metadata_kwargs)

return elements
else:
return _remove_element_metadata(
elements,
)
return remove_element_metadata(elements)

return wrapper

Expand Down Expand Up @@ -639,16 +634,11 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> List[Element]:
# NOTE(robinson) - Attached files have already run through this logic
# in their own partitioning function
if element.metadata.attached_to_filename is None:
_add_element_metadata(
element,
filetype=FILETYPE_TO_MIMETYPE[filetype],
)
add_element_metadata(element, filetype=FILETYPE_TO_MIMETYPE[filetype])

return elements
else:
return _remove_element_metadata(
elements,
)
return remove_element_metadata(elements)

return wrapper

Expand Down
Loading

0 comments on commit b59e4b6

Please sign in to comment.