-
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 4 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
Dict, | ||
Generic, | ||
Iterable, | ||
List, | ||
|
@@ -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 commentThe 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
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. Actually we can use |
||
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["CodecOptions[Mapping[str, Any]]"] = None, | ||
read_preference: Optional[_ServerMode] = None, | ||
write_concern: Optional[WriteConcern] = None, | ||
read_concern: Optional["ReadConcern"] = None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2023-present MongoDB, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Test typings in strict mode.""" | ||
import unittest | ||
from typing import TYPE_CHECKING, Any | ||
|
||
import pymongo | ||
from pymongo.collection import Collection | ||
from pymongo.database import Database | ||
|
||
|
||
def test_generic_arguments() -> None: | ||
"""Ensure known usages of generic arguments pass strict typing""" | ||
if not TYPE_CHECKING: | ||
raise unittest.SkipTest("Used for Type Checking Only") | ||
mongo_client: pymongo.MongoClient[dict[str, Any]] = pymongo.MongoClient() | ||
mongo_client.drop_database("foo") | ||
mongo_client.get_default_database() | ||
db = mongo_client.get_database("test_db") | ||
db = Database(mongo_client, "test_db") | ||
db.with_options() | ||
db.validate_collection("py_test") | ||
col = db.get_collection("py_test") | ||
col.insert_one({"abc": 123}) | ||
col = Collection(db, "py_test") | ||
col.with_options() |
Uh oh!
There was an error while loading. Please reload this page.