-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-3568 Intellisense highlights multiple PyMongo methods because of CodecOptions #1139
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
Changes from 13 commits
9d7ae96
598261b
52a5364
968f994
2fefac8
9b5bd67
7bcfcaf
f826b74
3571f3f
76b77df
c158f60
7dc82c7
aff48f5
84f682a
01bf36a
0ba5e7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ you get the error: "TypeError: 'type' object is not subscriptable". | |
import datetime | ||
import abc | ||
import enum | ||
from typing import Tuple, Generic, Optional, Mapping, Any, TypeVar, Type, Dict, Iterable, Tuple, MutableMapping, Callable, Union | ||
from typing import Tuple, Generic, Optional, Mapping, Any, TypeVar, Type, Dict, Iterable, Tuple, Callable, Union | ||
from pymongo.typings import _DocumentType, _DocumentTypeArg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's odd to have bson import from pymongo, even if it's just for typing. Can we reverse this so that _DocumentType and _DocumentTypeArg are defined in the bson package? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created |
||
|
||
|
||
class TypeEncoder(abc.ABC, metaclass=abc.ABCMeta): | ||
|
@@ -52,9 +53,6 @@ class TypeRegistry: | |
def __init__(self, type_codecs: Optional[Iterable[Codec]] = ..., fallback_encoder: Optional[Fallback] = ...) -> None: ... | ||
def __eq__(self, other: Any) -> Any: ... | ||
|
||
|
||
_DocumentType = TypeVar("_DocumentType", bound=Mapping[str, Any]) | ||
|
||
class DatetimeConversion(int, enum.Enum): | ||
DATETIME = ... | ||
DATETIME_CLAMP = ... | ||
|
@@ -82,7 +80,7 @@ class CodecOptions(Tuple, Generic[_DocumentType]): | |
) -> CodecOptions[_DocumentType]: ... | ||
|
||
# CodecOptions API | ||
def with_options(self, **kwargs: Any) -> CodecOptions[_DocumentType]: ... | ||
def with_options(self, **kwargs: Any) -> CodecOptions[_DocumentTypeArg]: ... | ||
|
||
def _arguments_repr(self) -> str: ... | ||
|
||
|
@@ -100,7 +98,7 @@ class CodecOptions(Tuple, Generic[_DocumentType]): | |
_fields: Tuple[str] | ||
|
||
|
||
DEFAULT_CODEC_OPTIONS: CodecOptions[MutableMapping[str, Any]] | ||
DEFAULT_CODEC_OPTIONS: "CodecOptions[Mapping[str, Any]]" | ||
_RAW_BSON_DOCUMENT_MARKER: int | ||
|
||
def _raw_document_class(document_class: Any) -> bool: ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ | |
InsertOneResult, | ||
UpdateResult, | ||
) | ||
from pymongo.typings import _CollationIn, _DocumentType, _Pipeline | ||
from pymongo.typings import _CollationIn, _DocumentType, _DocumentTypeArg, _Pipeline | ||
from pymongo.write_concern import WriteConcern | ||
|
||
_FIND_AND_MODIFY_DOC_FIELDS = {"value": 1} | ||
|
@@ -103,6 +103,7 @@ class ReturnDocument(object): | |
|
||
|
||
if TYPE_CHECKING: | ||
import bson | ||
from pymongo.client_session import ClientSession | ||
from pymongo.database import Database | ||
from pymongo.read_concern import ReadConcern | ||
|
@@ -116,7 +117,7 @@ def __init__( | |
database: "Database[_DocumentType]", | ||
name: str, | ||
create: Optional[bool] = False, | ||
codec_options: Optional[CodecOptions] = None, | ||
codec_options: Optional["CodecOptions[_DocumentTypeArg]"] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come this one can be "CodecOptions" not "bson.CodecOptions"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't make heads or tails of it, other than the fact that this a constructor. I tried removing the docstring from |
||
read_preference: Optional[_ServerMode] = None, | ||
write_concern: Optional[WriteConcern] = None, | ||
read_concern: Optional["ReadConcern"] = None, | ||
|
@@ -394,7 +395,7 @@ def database(self) -> "Database[_DocumentType]": | |
|
||
def with_options( | ||
self, | ||
codec_options: Optional[CodecOptions] = None, | ||
codec_options: Optional["bson.CodecOptions[_DocumentTypeArg]"] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What caused the change to add "bson." here? We don't need to do the same for ReadConcern/WriteConcern/etc.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was needed to satisfy sphinx:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's odd. I don't see those warning locally:
It would be great to avoid changing the type signature just because of a sphinx issue (bug?) if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We needed to switch to strings because on Python 3.7 we were getting: |
||
read_preference: Optional[_ServerMode] = None, | ||
write_concern: Optional[WriteConcern] = None, | ||
read_concern: Optional["ReadConcern"] = None, | ||
|
Uh oh!
There was an error while loading. Please reload this page.