Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Add B(bugbear) ruff rules #25520

Merged
merged 2 commits into from
Aug 28, 2024
Merged

Conversation

cbornet
Copy link
Collaborator

@cbornet cbornet commented Aug 17, 2024

No description provided.

Copy link

vercel bot commented Aug 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Aug 28, 2024 7:06am

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Ɑ: core Related to langchain-core 🤖:improvement Medium size change to existing code to handle new use-cases labels Aug 17, 2024
if hasattr(res, "target_run_id")
else str(run.id)
)
run_id = str(getattr(res, "target_run_id", run.id))
Copy link
Collaborator Author

@cbornet cbornet Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if res.target_run_id is None ?

@cbornet cbornet force-pushed the ruff-core-b branch 2 times, most recently from 5299dff to a26424a Compare August 17, 2024 12:35
@@ -516,15 +516,19 @@ def __copy__(self) -> _TracerCore:

def _end_trace(self, run: Run) -> Union[None, Coroutine[Any, Any, None]]:
"""End a trace for a run."""
return None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to PyCQA/flake8-bugbear#301
Do we prefer to ignore the rule with noqa ?

@cbornet cbornet force-pushed the ruff-core-b branch 7 times, most recently from bcddb7c to 1bbcf0b Compare August 17, 2024 15:20
@@ -568,7 +569,7 @@ def similarity_search_with_relevance_scores(
if similarity >= score_threshold
]
if len(docs_and_similarities) == 0:
warnings.warn(
logger.warning(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://docs.python.org/3/howto/logging.html#when-to-use-logging :

warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning
A logger’s warning() method if there is nothing the client application can do about the situation, but the event should still be noted

Copy link
Collaborator

@baskaryan baskaryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly curious to understand what impact changing warning stacklevel will have

@cbornet cbornet changed the title core: Add B(bugbear) ruff rules [core] Add B(bugbear) ruff rules Aug 21, 2024
@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Aug 21, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -748,7 +748,7 @@ def is_async_generator(
"""
return (
inspect.isasyncgenfunction(func)
or hasattr(func, "__call__")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was on purpose cc @hinthornw I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from https://docs.astral.sh/ruff/rules/unreliable-callable-check/
Is it a false positive ? Should the rule be ignored here ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here this is explicitly just a guard so that we don't err when checking inspect.isasyncgenfunction(func.__call__) in the next line, so i think it's a false positive.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could alternatiely do inspect.isasyncgenfunction(getattr(func, '__call__', None)) if we want the linter to be happy


def _on_retriever_error(self, run: Run) -> Union[None, Coroutine[Any, Any, None]]:
"""Process the Retriever Run upon error."""
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't make a ton of sense, its either an abstract method or it isn't

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like separate issue from this pr (having nothing is equivalent to returning None)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment: https://github.com/langchain-ai/langchain/pull/25520/files/dd1df352ffb2731807f10224b0919039782939d7#r1720771953
It's not an abstract method, but ruff thinks it should be if we don't add return None.
I can add noqa instead if you prefer.

Copy link
Member

@efriis efriis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you !!

@efriis efriis changed the title [core] Add B(bugbear) ruff rules core: Add B(bugbear) ruff rules Aug 22, 2024
@baskaryan baskaryan enabled auto-merge (squash) August 28, 2024 07:06
@baskaryan baskaryan merged commit ff0df5e into langchain-ai:master Aug 28, 2024
88 checks passed
@cbornet cbornet deleted the ruff-core-b branch August 28, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core 🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants