Skip to content

Commit

Permalink
Workaround Incompatible types in assignment (expression has type floa…
Browse files Browse the repository at this point in the history
…t, variable has type Double) [assignment]

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 17, 2023
1 parent d81cdb1 commit ffa5944
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- Fix `TypeError` on `parallel_bulk` ([#601](https://github.com/opensearch-project/opensearch-py/pull/601))
- Fix Amazon OpenSearch Serverless integration with LangChain ([#603](https://github.com/opensearch-project/opensearch-py/pull/603))
- Fix type of `Field.__setattr__` ([604](https://github.com/opensearch-project/opensearch-py/pull/604))
### Security

## [2.4.1]
Expand Down
27 changes: 26 additions & 1 deletion test_opensearchpy/test_helpers/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import pickle
from datetime import datetime
from hashlib import sha256
from typing import Any
from typing import Any, Union

from pytest import raises

Expand Down Expand Up @@ -648,3 +648,28 @@ class MySubDocWithNested(MyDoc):
},
"title": {"type": "keyword"},
}


def test_save_double(mock_client: Any) -> None:
class MyDocumentWithDouble(MyDoc):
a_double: Union[float, field.Double] = field.Double()

def save(
self,
using: Any = None,
index: Any = None,
validate: bool = True,
skip_empty: bool = True,
return_doc_meta: bool = False,
**kwargs: Any,
) -> Any:
if not self.a_double:
self.a_double = 3.14159265359
return super().save(
using, index, validate, skip_empty, return_doc_meta, **kwargs
)

md: Any = MyDocumentWithDouble()
with raises(ValidationException):
md.save(using="mock")
assert md.a_double == 3.14159265359

0 comments on commit ffa5944

Please sign in to comment.