Remove to_namespace and its user, since nothing triggers it
This commit is contained in:
@@ -101,29 +101,10 @@ class PageContext:
|
||||
def __getstate__(self):
|
||||
state = self.__dict__.copy()
|
||||
|
||||
# Use JSON serialization instead of Namespace
|
||||
try:
|
||||
options_json = self.options.model_dump_json_safe()
|
||||
state['options_json'] = options_json
|
||||
# Remove the OCROptions object to avoid pickle issues
|
||||
del state['options']
|
||||
except Exception:
|
||||
# Fallback: if JSON serialization fails, convert to namespace
|
||||
# This shouldn't happen but provides safety
|
||||
from argparse import Namespace
|
||||
|
||||
clean_options = Namespace()
|
||||
for key, value in vars(self.options.to_namespace()).items():
|
||||
if key.startswith('_'):
|
||||
continue
|
||||
try:
|
||||
import pickle
|
||||
|
||||
pickle.dumps(value)
|
||||
setattr(clean_options, key, value)
|
||||
except TypeError:
|
||||
continue
|
||||
state['options'] = clean_options
|
||||
options_json = self.options.model_dump_json_safe()
|
||||
state['options_json'] = options_json
|
||||
# Remove the OCROptions object to avoid pickle issues
|
||||
del state['options']
|
||||
|
||||
# Remove any potential references to Pydantic objects
|
||||
state.pop('_pdf_context', None)
|
||||
|
||||
@@ -190,21 +190,6 @@ class OCROptions(BaseModel):
|
||||
instance.extra_attrs = extra_attrs
|
||||
return instance
|
||||
|
||||
def to_namespace(self) -> Namespace:
|
||||
"""Convert back to argparse.Namespace for compatibility."""
|
||||
ns = Namespace()
|
||||
|
||||
# Add pydantic fields
|
||||
for field_name in type(self).model_fields:
|
||||
field_value = getattr(self, field_name)
|
||||
setattr(ns, field_name, field_value)
|
||||
|
||||
# Add extra attributes (including computed ones like lossless_reconstruction)
|
||||
for key, value in self.extra_attrs.items():
|
||||
setattr(ns, key, value)
|
||||
|
||||
return ns
|
||||
|
||||
@field_validator('languages')
|
||||
@classmethod
|
||||
def validate_languages(cls, v):
|
||||
|
||||
Reference in New Issue
Block a user