community[patch]: Fix remaining __inits__ in community (#22037)

Fixes the __init__ files in community to use __all__ which is statically
defined.
This commit is contained in:
Eugene Yurtsev 2024-05-22 13:42:17 -04:00 committed by GitHub
parent b7d08bf764
commit 36813d2f00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 49 additions and 29 deletions

View File

@ -168,6 +168,3 @@ def __getattr__(name: str) -> Any:
module = importlib.import_module(_module_lookup[name])
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())

View File

@ -81,6 +81,3 @@ def __getattr__(name: str) -> Any:
module = importlib.import_module(_module_lookup[name])
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())

View File

@ -137,6 +137,3 @@ def __getattr__(name: str) -> Any:
module = importlib.import_module(_module_lookup[name])
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())

View File

@ -29,8 +29,6 @@ if TYPE_CHECKING:
Wikipedia,
)
__all__ = ["DocstoreFn", "InMemoryDocstore", "Wikipedia"]
_module_lookup = {
"DocstoreFn": "langchain_community.docstore.arbitrary_fn",
"InMemoryDocstore": "langchain_community.docstore.in_memory",
@ -45,4 +43,4 @@ def __getattr__(name: str) -> Any:
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())
__all__ = ["DocstoreFn", "InMemoryDocstore", "Wikipedia"]

View File

@ -6,7 +6,7 @@ if TYPE_CHECKING:
FlashrankRerank,
)
from langchain_community.document_compressors.jina_rerank import (
JinaRerank, # noqa: F401
JinaRerank,
)
from langchain_community.document_compressors.llmlingua_filter import (
LLMLinguaCompressor,
@ -15,7 +15,6 @@ if TYPE_CHECKING:
OpenVINOReranker,
)
__all__ = ["LLMLinguaCompressor", "OpenVINOReranker", "FlashrankRerank"]
_module_lookup = {
"LLMLinguaCompressor": "langchain_community.document_compressors.llmlingua_filter",
@ -32,4 +31,4 @@ def __getattr__(name: str) -> Any:
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())
__all__ = ["LLMLinguaCompressor", "OpenVINOReranker", "FlashrankRerank", "JinaRerank"]

View File

@ -1,5 +1,36 @@
import importlib
from typing import Any
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from langchain_community.document_loaders.parsers.audio import (
OpenAIWhisperParser,
)
from langchain_community.document_loaders.parsers.doc_intelligence import (
AzureAIDocumentIntelligenceParser,
)
from langchain_community.document_loaders.parsers.docai import (
DocAIParser,
)
from langchain_community.document_loaders.parsers.grobid import (
GrobidParser,
)
from langchain_community.document_loaders.parsers.html import (
BS4HTMLParser,
)
from langchain_community.document_loaders.parsers.language import (
LanguageParser,
)
from langchain_community.document_loaders.parsers.pdf import (
PDFMinerParser,
PDFPlumberParser,
PyMuPDFParser,
PyPDFium2Parser,
PyPDFParser,
)
from langchain_community.document_loaders.parsers.vsdx import (
VsdxParser,
)
_module_lookup = {
"AzureAIDocumentIntelligenceParser": "langchain_community.document_loaders.parsers.doc_intelligence", # noqa: E501
@ -24,4 +55,17 @@ def __getattr__(name: str) -> Any:
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())
__all__ = [
"AzureAIDocumentIntelligenceParser",
"BS4HTMLParser",
"DocAIParser",
"GrobidParser",
"LanguageParser",
"OpenAIWhisperParser",
"PDFMinerParser",
"PDFPlumberParser",
"PyMuPDFParser",
"PyPDFParser",
"PyPDFium2Parser",
"VsdxParser",
]

View File

@ -93,6 +93,3 @@ def __getattr__(name: str) -> Any:
module = importlib.import_module(_module_lookup[name])
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())

View File

@ -57,6 +57,3 @@ def __getattr__(name: str) -> Any:
module = importlib.import_module(_module_lookup[name])
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())

View File

@ -496,6 +496,3 @@ def __getattr__(name: str) -> Any:
module = importlib.import_module(_module_lookup[name])
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = list(_module_lookup.keys())

View File

@ -4,8 +4,6 @@ import importlib
from pathlib import Path
from typing import List, Tuple
import pytest
COMMUNITY_ROOT = Path(__file__).parent.parent.parent / "langchain_community"
ALL_COMMUNITY_GLOB = COMMUNITY_ROOT.as_posix() + "/**/*.py"
HERE = Path(__file__).parent
@ -68,7 +66,6 @@ def _check_correct_or_not_defined__all__(code: str) -> bool:
return all_good
@pytest.mark.xfail
def test_no_dynamic__all__() -> None:
"""Verify that __all__ is not computed at runtime.