mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-03 02:06:33 +00:00
core: Add ruff rules G, FA, INP, AIR and ISC (#29334)
Fixes mostly for rules G. See https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
This commit is contained in:
parent
e4515f308f
commit
026de908eb
@ -282,13 +282,17 @@ def handle_event(
|
|||||||
else:
|
else:
|
||||||
handler_name = handler.__class__.__name__
|
handler_name = handler.__class__.__name__
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"NotImplementedError in {handler_name}.{event_name}"
|
"NotImplementedError in %s.%s callback: %s",
|
||||||
f" callback: {repr(e)}"
|
handler_name,
|
||||||
|
event_name,
|
||||||
|
repr(e),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Error in {handler.__class__.__name__}.{event_name} callback:"
|
"Error in %s.%s callback: %s",
|
||||||
f" {repr(e)}"
|
handler.__class__.__name__,
|
||||||
|
event_name,
|
||||||
|
repr(e),
|
||||||
)
|
)
|
||||||
if handler.raise_error:
|
if handler.raise_error:
|
||||||
raise
|
raise
|
||||||
@ -328,7 +332,7 @@ def _run_coros(coros: list[Coroutine[Any, Any, Any]]) -> None:
|
|||||||
try:
|
try:
|
||||||
runner.run(coro)
|
runner.run(coro)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Error in callback coroutine: {repr(e)}")
|
logger.warning("Error in callback coroutine: %s", repr(e))
|
||||||
|
|
||||||
# Run pending tasks scheduled by coros until they are all done
|
# Run pending tasks scheduled by coros until they are all done
|
||||||
while pending := asyncio.all_tasks(runner.get_loop()):
|
while pending := asyncio.all_tasks(runner.get_loop()):
|
||||||
@ -340,7 +344,7 @@ def _run_coros(coros: list[Coroutine[Any, Any, Any]]) -> None:
|
|||||||
try:
|
try:
|
||||||
asyncio.run(coro)
|
asyncio.run(coro)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Error in callback coroutine: {repr(e)}")
|
logger.warning("Error in callback coroutine: %s", repr(e))
|
||||||
|
|
||||||
|
|
||||||
async def _ahandle_event_for_handler(
|
async def _ahandle_event_for_handler(
|
||||||
@ -382,12 +386,17 @@ async def _ahandle_event_for_handler(
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"NotImplementedError in {handler.__class__.__name__}.{event_name}"
|
"NotImplementedError in %s.%s callback: %s",
|
||||||
f" callback: {repr(e)}"
|
handler.__class__.__name__,
|
||||||
|
event_name,
|
||||||
|
repr(e),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Error in {handler.__class__.__name__}.{event_name} callback: {repr(e)}"
|
"Error in %s.%s callback: %s",
|
||||||
|
handler.__class__.__name__,
|
||||||
|
event_name,
|
||||||
|
repr(e),
|
||||||
)
|
)
|
||||||
if handler.raise_error:
|
if handler.raise_error:
|
||||||
raise
|
raise
|
||||||
@ -2386,7 +2395,8 @@ def _configure(
|
|||||||
"Unable to load requested LangChainTracer."
|
"Unable to load requested LangChainTracer."
|
||||||
" To disable this warning,"
|
" To disable this warning,"
|
||||||
" unset the LANGCHAIN_TRACING_V2 environment variables.\n"
|
" unset the LANGCHAIN_TRACING_V2 environment variables.\n"
|
||||||
f"{repr(e)}",
|
"%s",
|
||||||
|
repr(e),
|
||||||
)
|
)
|
||||||
if run_tree is not None:
|
if run_tree is not None:
|
||||||
for handler in callback_manager.handlers:
|
for handler in callback_manager.handlers:
|
||||||
|
@ -119,8 +119,9 @@ class _TracerCore(ABC):
|
|||||||
else:
|
else:
|
||||||
if self.log_missing_parent:
|
if self.log_missing_parent:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Parent run {run.parent_run_id} not found for run {run.id}."
|
"Parent run %s not found for run %s. Treating as a root run.",
|
||||||
" Treating as a root run."
|
run.parent_run_id,
|
||||||
|
run.id,
|
||||||
)
|
)
|
||||||
run.parent_run_id = None
|
run.parent_run_id = None
|
||||||
run.trace_id = run.id
|
run.trace_id = run.id
|
||||||
|
@ -134,11 +134,11 @@ class EvaluatorCallbackHandler(BaseTracer):
|
|||||||
run,
|
run,
|
||||||
source_run_id=cb.latest_run.id if cb.latest_run else None,
|
source_run_id=cb.latest_run.id if cb.latest_run else None,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(
|
logger.exception(
|
||||||
f"Error evaluating run {run.id} with "
|
"Error evaluating run %s with %s",
|
||||||
f"{evaluator.__class__.__name__}: {repr(e)}",
|
run.id,
|
||||||
exc_info=True,
|
evaluator.__class__.__name__,
|
||||||
)
|
)
|
||||||
raise
|
raise
|
||||||
example_id = str(run.reference_example_id)
|
example_id = str(run.reference_example_id)
|
||||||
@ -202,7 +202,7 @@ class EvaluatorCallbackHandler(BaseTracer):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if self.skip_unfinished and not run.outputs:
|
if self.skip_unfinished and not run.outputs:
|
||||||
logger.debug(f"Skipping unfinished run {run.id}")
|
logger.debug("Skipping unfinished run %s", run.id)
|
||||||
return
|
return
|
||||||
run_ = run.copy()
|
run_ = run.copy()
|
||||||
run_.reference_example_id = self.example_id
|
run_.reference_example_id = self.example_id
|
||||||
|
@ -95,7 +95,9 @@ def extract_sub_links(
|
|||||||
absolute_paths.add(absolute_path)
|
absolute_paths.add(absolute_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if continue_on_failure:
|
if continue_on_failure:
|
||||||
logger.warning(f"Unable to load link {link}. Raised exception:\n\n{e}")
|
logger.warning(
|
||||||
|
"Unable to load link %s. Raised exception:\n\n%s", link, e
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ def _get_key(
|
|||||||
# We couldn't find the key in any of the scopes
|
# We couldn't find the key in any of the scopes
|
||||||
|
|
||||||
if warn:
|
if warn:
|
||||||
logger.warn(f"Could not find key '{key}'")
|
logger.warning("Could not find key '%s'", key)
|
||||||
|
|
||||||
if keep:
|
if keep:
|
||||||
return f"{def_ldel} {key} {def_rdel}"
|
return f"{def_ldel} {key} {def_rdel}"
|
||||||
|
@ -117,8 +117,8 @@ class VectorStore(ABC):
|
|||||||
def embeddings(self) -> Optional[Embeddings]:
|
def embeddings(self) -> Optional[Embeddings]:
|
||||||
"""Access the query embedding object if available."""
|
"""Access the query embedding object if available."""
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"The embeddings property has not been "
|
"The embeddings property has not been implemented for %s",
|
||||||
f"implemented for {self.__class__.__name__}"
|
self.__class__.__name__,
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -573,8 +573,9 @@ class VectorStore(ABC):
|
|||||||
]
|
]
|
||||||
if len(docs_and_similarities) == 0:
|
if len(docs_and_similarities) == 0:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"No relevant docs were retrieved using the relevance score"
|
"No relevant docs were retrieved using the "
|
||||||
f" threshold {score_threshold}"
|
"relevance score threshold %s",
|
||||||
|
score_threshold,
|
||||||
)
|
)
|
||||||
return docs_and_similarities
|
return docs_and_similarities
|
||||||
|
|
||||||
@ -621,8 +622,9 @@ class VectorStore(ABC):
|
|||||||
]
|
]
|
||||||
if len(docs_and_similarities) == 0:
|
if len(docs_and_similarities) == 0:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"No relevant docs were retrieved using the relevance score"
|
"No relevant docs were retrieved using the "
|
||||||
f" threshold {score_threshold}"
|
"relevance score threshold %s",
|
||||||
|
score_threshold,
|
||||||
)
|
)
|
||||||
return docs_and_similarities
|
return docs_and_similarities
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ target-version = "py39"
|
|||||||
|
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = [ "ANN", "ASYNC", "B", "C4", "COM", "DJ", "E", "EM", "EXE", "F", "FLY", "FURB", "I", "ICN", "INT", "LOG", "N", "NPY", "PD", "PIE", "PLW", "PTH", "Q", "RSE", "S", "SIM", "SLOT", "T10", "T201", "TC", "TID", "TRY", "UP", "W", "YTT",]
|
select = [ "AIR", "ANN", "ASYNC", "B", "C4", "COM", "DJ", "E", "EM", "EXE", "F", "FA", "FAST", "FLY", "FURB", "G", "I", "ICN", "INP","INT", "ISC", "LOG", "N", "NPY", "PD", "PIE", "PLW", "PTH", "Q", "RSE", "S", "SIM", "SLOT", "T10", "T20", "TC", "TID", "TRY", "UP", "W", "YTT",]
|
||||||
ignore = [ "ANN401", "COM812", "UP007", "S110", "S112", "TC001", "TC002", "TC003"]
|
ignore = [ "ANN401", "COM812", "FA100", "ISC001", "S110", "S112", "TC001", "TC002", "TC003", "UP007",]
|
||||||
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
|
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
|
||||||
flake8-annotations.allow-star-arg-any = true
|
flake8-annotations.allow-star-arg-any = true
|
||||||
flake8-annotations.mypy-init-return = true
|
flake8-annotations.mypy-init-return = true
|
||||||
@ -102,4 +102,4 @@ classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_ini
|
|||||||
"tests/unit_tests/runnables/test_runnable.py" = [ "E501",]
|
"tests/unit_tests/runnables/test_runnable.py" = [ "E501",]
|
||||||
"tests/unit_tests/runnables/test_graph.py" = [ "E501",]
|
"tests/unit_tests/runnables/test_graph.py" = [ "E501",]
|
||||||
"tests/**" = [ "S",]
|
"tests/**" = [ "S",]
|
||||||
"scripts/**" = [ "S",]
|
"scripts/**" = [ "INP", "S",]
|
||||||
|
0
libs/core/tests/unit_tests/caches/__init__.py
Normal file
0
libs/core/tests/unit_tests/caches/__init__.py
Normal file
@ -862,7 +862,7 @@ def test_get_output_messages_with_value_error() -> None:
|
|||||||
with_history.bound.invoke([HumanMessage(content="hello")], config)
|
with_history.bound.invoke([HumanMessage(content="hello")], config)
|
||||||
excepted = (
|
excepted = (
|
||||||
"Expected str, BaseMessage, List[BaseMessage], or Tuple[BaseMessage]."
|
"Expected str, BaseMessage, List[BaseMessage], or Tuple[BaseMessage]."
|
||||||
+ (f" Got {illegal_bool_message}.")
|
f" Got {illegal_bool_message}."
|
||||||
)
|
)
|
||||||
assert excepted in str(excinfo.value)
|
assert excepted in str(excinfo.value)
|
||||||
|
|
||||||
@ -874,6 +874,6 @@ def test_get_output_messages_with_value_error() -> None:
|
|||||||
with_history.bound.invoke([HumanMessage(content="hello")], config)
|
with_history.bound.invoke([HumanMessage(content="hello")], config)
|
||||||
excepted = (
|
excepted = (
|
||||||
"Expected str, BaseMessage, List[BaseMessage], or Tuple[BaseMessage]."
|
"Expected str, BaseMessage, List[BaseMessage], or Tuple[BaseMessage]."
|
||||||
+ (f" Got {illegal_int_message}.")
|
f" Got {illegal_int_message}."
|
||||||
)
|
)
|
||||||
assert excepted in str(excinfo.value)
|
assert excepted in str(excinfo.value)
|
||||||
|
@ -994,7 +994,7 @@ def test__convert_typed_dict_to_openai_function_fail(typed_dict: type) -> None:
|
|||||||
)
|
)
|
||||||
def test_convert_union_type_py_39() -> None:
|
def test_convert_union_type_py_39() -> None:
|
||||||
@tool
|
@tool
|
||||||
def magic_function(input: int | float) -> str:
|
def magic_function(input: int | float) -> str: # noqa: FA102
|
||||||
"""Compute a magic function."""
|
"""Compute a magic function."""
|
||||||
|
|
||||||
result = convert_to_openai_function(magic_function)
|
result = convert_to_openai_function(magic_function)
|
||||||
|
Loading…
Reference in New Issue
Block a user