Skip to content

Commit

Permalink
fix(bson): missing top level BSON class (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbdchd authored Jan 28, 2021
1 parent 4b34945 commit 7cfced9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion s/lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -eux
set -ex

# format code
if [[ $CI ]]; then
Expand Down
8 changes: 7 additions & 1 deletion tests/test_mongoengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import mongoengine
import pymongo
from bson import ObjectId
from bson import BSON, ObjectId
from mongoengine import Document, EmbeddedDocument, QuerySet, fields
from pymongo.collation import Collation, CollationStrength

Expand Down Expand Up @@ -173,6 +173,12 @@ def main() -> None:
Post().reload()


def test_bson() -> None:
doc = {"foo": "bar", "buzz": True}
data = BSON.encode(doc)
assert BSON.decode(data) == doc


def test_pymongo() -> None:
pymongo.ALL
pymongo.ASCENDING
Expand Down
15 changes: 14 additions & 1 deletion typings/bson/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
from typing import Any
from typing import Any, Mapping

from bson.codec_options import CodecOptions
from bson.objectid import ObjectId
from bson.son import SON

def decode_iter(data: bytes, codec_options: CodecOptions = ...) -> Any: ...

class BSON(bytes):
@classmethod
def encode(
cls,
document: Mapping[str, Any],
check_keys: bool = ...,
codec_options: CodecOptions = ...,
) -> BSON: ...
def decode( # type: ignore [override]
self,
codec_options: CodecOptions = ...,
) -> Any: ...

__all__ = ["ObjectId", "SON", "decode_iter", "CodecOptions"]

0 comments on commit 7cfced9

Please sign in to comment.