Skip to content

Commit

Permalink
fix: ordered fields of index type is more broad and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu-CZ committed Apr 13, 2023
1 parent 4122c26 commit 461340e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.0.6] - 2023-04-13

### Fixed

- typing of required fields of index more broad

## [0.0.5] - 2023-04-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/mongomancy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Abstraction layer of PyMongo with auto-reconnect and collection initialization support.
"""
__version__ = "0.0.5"
__version__ = "0.0.6"

# pymongo shortcuts
import pymongo
Expand Down
12 changes: 11 additions & 1 deletion src/mongomancy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
import time
import traceback
from dataclasses import dataclass
from typing import List, Tuple, Union, TypeVar, Mapping, Any, Optional, Dict, Iterable
from typing import (
List,
Tuple,
Union,
TypeVar,
Mapping,
Any,
Optional,
Dict,
Iterable,
)

import pymongo
import pymongo.command_cursor
Expand Down
17 changes: 9 additions & 8 deletions src/mongomancy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from dataclasses import dataclass, field
from typing import (
OrderedDict,
OrderedDict as OrderedDictType,
List,
Tuple,
Sequence,
Expand All @@ -14,9 +14,8 @@
Any,
Iterable,
Callable,
TypeVar,
)

from collections import OrderedDict
import pymongo.database
import pymongo.results
from bson import ObjectId
Expand All @@ -37,16 +36,18 @@
BsonDict = Mapping[str, Bson]
BsonList = Sequence[Bson]

OrderedDictType = OrderedDict
OrderedFields = OrderedDictType[str, Union[str, int]]
if sys.version_info >= (3, 7):
OrderedDictType = TypeVar("OrderedDictType", bound=Dict)
OrderedFields = Dict[str, Union[str, int]]

OrderedPairs = Union[OrderedFields, Sequence[Tuple[str, Union[str, int]]]]


@dataclass(init=False)
class Index:
"""Collection Index data container"""

fields: OrderedDictType[str, Union[str, int]]
fields: OrderedDict[str, Union[str, int]]
name: Optional[str]
unique: Optional[bool]

Expand All @@ -58,11 +59,11 @@ class Index:

def __init__(
self,
fields: OrderedDictType[str, Union[str, int]],
fields: OrderedPairs,
name: Optional[str] = None,
unique: Optional[bool] = False,
) -> None:
self.fields = fields
self.fields = OrderedDict(fields)
self.name = name
self.unique = unique

Expand Down

0 comments on commit 461340e

Please sign in to comment.