fix _strip_extras helper function #6427
Open
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello everyone !
While reading the code of
libs/langgraph/langgraph/channels/binop.py, I found out that the helper function_strip_extrasmay have a small typo:There is an issue because the second part of the function will never be reached because if
hasattr(t, "__origin__") == Falsethenhasattr(t, "__origin__") and t.__origin__ in (Required, NotRequired) == Falsetoo.The original implementation from typing_extension is github link :
We can see that they don't use
hasattr(t, "__origin__")as first condition butisinstance(t, typing._AnnotatedAlias)which specifically targets annotations.This code was introduced in this commit. According to the docstring of the function, the first two lines are supposed to target the annotations specifically but I am not 100% certain that changing
if hasattr(t, "__origin__"):toif isinstance(t, typing._AnnotatedAlias):will not break other parts of the code (moreover there might be a reason the author of this commit made that choice.).But switching the two ifs seams to fix the function behaviour without breaking any existing code, this is why I propose this small fix.
Sample code for the bug
We can exhibit the bug when manipulating the
BinaryOperatorAggregateobject:returns
AttributeError: 'object' object has no attribute 'append'But
works fine.
Higher level object manipulation
It looks like this code has no impact over higher level objects because the
BinaryOperatorAggregatevalues are always updated via theupdate()method that will handleMISSINGflag. theBinaryOperatorAggregate(...).valueis never assigned directly in the code.