Skip to content

Commit 98d0304

Browse files
committed
Merge remote-tracking branch 'upstream/async-improvements' into async-improvements
2 parents 185ac5b + e736221 commit 98d0304

File tree

10 files changed

+4831
-2959
lines changed

10 files changed

+4831
-2959
lines changed

.evergreen/config.yml

Lines changed: 43 additions & 2626 deletions
Large diffs are not rendered by default.

.evergreen/generated_configs/tasks.yml

Lines changed: 2929 additions & 0 deletions
Large diffs are not rendered by default.

.evergreen/generated_configs/variants.yml

Lines changed: 1283 additions & 0 deletions
Large diffs are not rendered by default.

.evergreen/scripts/generate_config.py

Lines changed: 274 additions & 69 deletions
Large diffs are not rendered by default.

THIRD-PARTY-NOTICES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
7373
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7474

7575

76-
3) License Notice for async_lock.py
76+
3) License Notice for _asyncio_lock.py
7777
-----------------------------------------
7878

7979
1. This LICENSE AGREEMENT is between the Python Software Foundation

bson/binary.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import struct
1717
from dataclasses import dataclass
1818
from enum import Enum
19-
from typing import TYPE_CHECKING, Any, Sequence, Tuple, Type, Union
19+
from typing import TYPE_CHECKING, Any, Optional, Sequence, Tuple, Type, Union
2020
from uuid import UUID
2121

2222
"""Tools for representing BSON binary data.
@@ -400,24 +400,35 @@ def as_uuid(self, uuid_representation: int = UuidRepresentation.STANDARD) -> UUI
400400
@classmethod
401401
def from_vector(
402402
cls: Type[Binary],
403-
vector: list[int, float],
404-
dtype: BinaryVectorDtype,
405-
padding: int = 0,
403+
vector: Union[BinaryVector, list[int, float]],
404+
dtype: Optional[BinaryVectorDtype] = None,
405+
padding: Optional[int] = None,
406406
) -> Binary:
407-
"""**(BETA)** Create a BSON :class:`~bson.binary.Binary` of Vector subtype from a list of Numbers.
407+
"""**(BETA)** Create a BSON :class:`~bson.binary.Binary` of Vector subtype.
408408
409409
To interpret the representation of the numbers, a data type must be included.
410410
See :class:`~bson.binary.BinaryVectorDtype` for available types and descriptions.
411411
412412
The dtype and padding are prepended to the binary data's value.
413413
414-
:param vector: List of values
414+
:param vector: Either a List of values, or a :class:`~bson.binary.BinaryVector` dataclass.
415415
:param dtype: Data type of the values
416416
:param padding: For fractional bytes, number of bits to ignore at end of vector.
417417
:return: Binary packed data identified by dtype and padding.
418418
419419
.. versionadded:: 4.10
420420
"""
421+
if isinstance(vector, BinaryVector):
422+
if dtype or padding:
423+
raise ValueError(
424+
"The first argument, vector, has type BinaryVector. "
425+
"dtype or padding cannot be separately defined, but were."
426+
)
427+
dtype = vector.dtype
428+
padding = vector.padding
429+
vector = vector.data # type: ignore
430+
431+
padding = 0 if padding is None else padding
421432
if dtype == BinaryVectorDtype.INT8: # pack ints in [-128, 127] as signed int8
422433
format_str = "b"
423434
if padding:
@@ -432,7 +443,7 @@ def from_vector(
432443
raise NotImplementedError("%s not yet supported" % dtype)
433444

434445
metadata = struct.pack("<sB", dtype.value, padding)
435-
data = struct.pack(f"<{len(vector)}{format_str}", *vector)
446+
data = struct.pack(f"<{len(vector)}{format_str}", *vector) # type: ignore
436447
return cls(metadata + data, subtype=VECTOR_SUBTYPE)
437448

438449
def as_vector(self) -> BinaryVector:

0 commit comments

Comments
 (0)