-
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
Conversation
pymongo/collection.py
Outdated
@@ -116,7 +117,7 @@ def __init__( | |||
database: "Database[_DocumentType]", | |||
name: str, | |||
create: Optional[bool] = False, | |||
codec_options: Optional[CodecOptions] = None, | |||
codec_options: Optional["CodecOptions[Mapping[str, Any]]"] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to use a generic TypeVar for CodecOptions instead of hardcoding Mapping[str, Any]
to avoid this failure?:
Found 1 error in 1 file (checked 83 source files)
pymongo/mongo_client.py:2054: error: Argument "codec_options" to "get_database"
of "MongoClient" has incompatible type "CodecOptions[MutableMapping[str, Any]]";
expected "Optional[CodecOptions[Mapping[str, Any]]]" [arg-type]
codec_options=DEFAULT_CODEC_OPTIONS,
^~~~~~~~~~~~~~~~~~~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we can use [_DocumentType]
everywhere and satisfy pyright
in strict mode.
The link check failure is expected until we merge this PR, since the file path in the link changes. |
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed to satisfy sphinx:
/home/docs/checkouts/readthedocs.org/user_builds/pymongo/checkouts/1139/pymongo/collection.py:docstring of pymongo.collection.Collection.with_options:: WARNING: more than one target found for cross-reference 'CodecOptions': bson.codec_options.CodecOptions, bson.CodecOptions
/home/docs/checkouts/readthedocs.org/user_builds/pymongo/checkouts/1139/pymongo/database.py:docstring of pymongo.database.Database:: WARNING: more than one target found for cross-reference 'CodecOptions': bson.codec_options.CodecOptions, bson.CodecOptions
/home/docs/checkouts/readthedocs.org/user_builds/pymongo/checkouts/1139/pymongo/database.py:docstring of pymongo.database.Database.create_collection:: WARNING: more than one target found for cross-reference 'CodecOptions': bson.codec_options.CodecOptions, bson.CodecOptions
/home/docs/checkouts/readthedocs.org/user_builds/pymongo/checkouts/1139/pymongo/database.py:docstring of pymongo.database.Database.get_collection:: WARNING: more than one target found for cross-reference 'CodecOptions': bson.codec_options.CodecOptions, bson.CodecOptions
/home/docs/checkouts/readthedocs.org/user_builds/pymongo/checkouts/1139/pymongo/database.py:docstring of pymongo.database.Database.with_options:: WARNING: more than one target found for cross-reference 'CodecOptions': bson.codec_options.CodecOptions, bson.CodecOptions
/home/docs/checkouts/readthedocs.org/user_builds/pymongo/checkouts/1139/pymongo/mongo_client.py:docstring of pymongo.mongo_client.MongoClient.get_default_database:: WARNING: more than one target found for cross-reference 'CodecOptions': bson.codec_options.CodecOptions, bson.CodecOptions
/home/docs/checkouts/readthedocs.org/user_builds/pymongo/checkouts/1139/pymongo/mongo_client.py:docstring of pymongo.mongo_client.MongoClient.get_database:: WARNING: more than one target found for cross-reference 'CodecOptions': bson.codec_options.CodecOptions, bson.CodecOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's odd. I don't see those warning locally:
python -m sphinx -b html doc doc/_build/4.4.0.dev0
Running Sphinx v4.5.0
loading pickled environment... failed
failed: build environment version not current
loading intersphinx inventory from https://www.gevent.org/objects.inv...
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 83 source files that are out of date
updating environment: [new config] 83 added, 0 changed, 0 removed
reading sources... [100%] tutorial
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] tutorial
generating indices... genindex py-modindex done
writing additional pages... search done
copying images... [100%] static/periodic-executor-refs.png
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.
The HTML pages are in doc/_build/4.4.0.dev0.
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 comment
The 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 comment
The 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: TypeError: 'type' object is not subscriptable
bson/codec_options.pyi
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I created bson/typings.py
and shuffled things around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last question.
@@ -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 comment
The 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 comment
The 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 with_options
and it still failed.
No description provided.