-
Notifications
You must be signed in to change notification settings - Fork 223
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
fix: raise exception when type of DocList is object #1794
Conversation
docarray/array/doc_list/doc_list.py
Outdated
else: | ||
return super().__class_getitem__(item) | ||
|
||
if isinstance(item, object) and not isinstance(item, TypeVar): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a check isinstance(item, TypeVar)
since item of TypeVar
was also being passed when __class_getitem__
was called
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1794 +/- ##
==========================================
+ Coverage 84.24% 84.81% +0.56%
==========================================
Files 135 135
Lines 8899 8901 +2
==========================================
+ Hits 7497 7549 +52
+ Misses 1402 1352 -50
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Hey @punndcoder28, please make sure to add relevant tests for this |
08b7e7b
to
8621817
Compare
@@ -337,8 +337,14 @@ def __class_getitem__(cls, item: Union[Type[BaseDoc], TypeVar, str]): | |||
|
|||
if isinstance(item, type) and safe_issubclass(item, BaseDoc): | |||
return AnyDocArray.__class_getitem__.__func__(cls, item) # type: ignore | |||
else: | |||
return super().__class_getitem__(item) | |||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we better have an elif
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since each condition has a terminating condition from the function wouldn't multiple if
's be similar to elif
? If there was a scenario like below an elif
would definitely make it much better. In the above case, we check the instance of item
and based on the condition we return a type or raise an exception. But if the code base follows if ... elif ... else
blocks I would love to keep it uniform so that it is easy to maintain
computation
if condn1:
computation = value1
elif condn2:
computation = value2
else:
computation = value3
return computation
Will fix the failing tests related to new changes |
@JoanFM Can we pass string literal as types for a class? Like so
This is being done here docarray/tests/units/array/test_array.py Line 383 in 8f32866
|
2144b3c
to
1a727be
Compare
u can in the type hints |
Signed-off-by: punndcoder28 <puneethk.2899@gmail.com>
1a727be
to
8266238
Compare
DocList
without causing code to raise expection as mentioned in Bug with DocList[] #1782Test Plan - Running the below code raises exception
Exception raise