Skip to content

PYTHON-3813 add types to pool.py #1318

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

Merged
merged 29 commits into from
Aug 5, 2023
Merged

Conversation

sleepyStick
Copy link
Contributor

@sleepyStick sleepyStick marked this pull request as ready for review August 3, 2023 02:03
@sleepyStick sleepyStick requested a review from a team as a code owner August 3, 2023 02:03
@sleepyStick sleepyStick requested review from NoahStapp and removed request for a team August 3, 2023 02:03
@ShaneHarvey
Copy link
Member

Sorry could you fix the merge conflicts and then I'll review this asap?

@sleepyStick
Copy link
Contributor Author

yeah, just fixed merge conflicts! Sorry, I didn't notice them earlier

self.socket_checker = SocketChecker()
self.oidc_token_gen_id = None
self.compression_context: Union[SnappyContext, ZlibContext, ZstdContext, None] = None
self.socket_checker: SocketChecker = SocketChecker()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is SocketChecker necessary here? It should be redundant here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this one is interesting. I agree that it feels redundant but without it mypy fails. I can take it away so you can see what the test failure would look like if that'd help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just did this commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the error this? What does SocketChecker have to do with this?:

Found 2 errors in 1 file (checked 85 source files)
pymongo/pool.py: note: In function "_configured_socket":
pymongo/pool.py:12[42](https://github.com/mongodb/mongo-python-driver/actions/runs/5757722911/job/15609185080#step:5:43): error: Incompatible types in assignment (expression has
type "_sslConn", variable has type "socket")  [assignment]
                    sock = ssl_context.wrap_socket(sock, server_hostname=h...
                           ^
pymongo/pool.py:12[44](https://github.com/mongodb/mongo-python-driver/actions/runs/5757722911/job/15609185080#step:5:45): error: Incompatible types in assignment (expression has
type "_sslConn", variable has type "socket")  [assignment]
                    sock = ssl_context.wrap_socket(sock)
                           ^
typecheck-mypy: exit 1 (14.39 seconds) /home/runner/work/mongo-python-driver/mongo-python-driver> mypy --install-types --non-interactive bson gridfs tools pymongo pid=1865

Copy link
Contributor Author

@sleepyStick sleepyStick Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait interesting, the error i get when i run it locally is this:

typecheck-mypy: commands[1]> mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude 'test/mypy_fails/*.*' --exclude test/conftest.py test
Found 1 error in 1 file (checked 125 source files)
pymongo/pool.py:83: note: In module imported here,
test/pymongo_mocks.py:26: note: ... from here:
pymongo/network.py: note: In function "wait_for_read":
pymongo/network.py:303: error: Cannot determine type of "socket_checker"  [has-type]
                    readable = conn.socket_checker.select(sock, read=True, timeout=timeout)
                               ^~~~~~~~~~~~~~~~~~~
typecheck-mypy: exit 1 (10.22 seconds) /Users/iris.ho/GitHub/mongo-python-driver> mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude 'test/mypy_fails/*.*' --exclude test/conftest.py test pid=95467
.pkg: _exit> python /Users/iris.ho/Library/Python/3.9/lib/python/site-packages/pyproject_api/_backend.py True setuptools.build_meta
  typecheck-mypy: FAIL code 1 (18.80=setup[6.96]+cmd[1.62,10.22] seconds)
  evaluation failed :( (18.87 seconds)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm when I run tox locally I get a different error:

pymongo/pool.py:83: note: In module imported here,
test/pymongo_mocks.py:26: note: ... from here:
pymongo/network.py: note: In function "wait_for_read":
pymongo/network.py:303: error: Cannot determine type of "socket_checker"  [has-type]
                    readable = conn.socket_checker.select(sock, read=True, timeout=timeout)
                               ^~~~~~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 125 source files)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does look like adding SocketChecker as a type here is required.

bson/typings.py Outdated
@@ -24,6 +24,6 @@

# Common Shared Types.
_DocumentOut = Union[MutableMapping[str, Any], "RawBSONDocument"]
_DocumentType = TypeVar("_DocumentType", bound=Mapping[str, Any])
_DocumentType = TypeVar("_DocumentType", bound=Mapping[str, Any], covariant=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why does this need covariant=True now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pymongo/pool.py Outdated
@@ -808,7 +860,7 @@ def _hello(self, cluster_time, topology_version, heartbeat_frequency):
self.generation = self.pool_gen.get(self.service_id)
return hello

def _next_reply(self):
def _next_reply(self) -> Mapping[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to Dict[str, Any], then we can remove the covariant=True.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, done.

@sleepyStick sleepyStick merged commit e0b8b36 into mongodb:master Aug 5, 2023
@sleepyStick sleepyStick deleted the PYTHON-3813 branch August 5, 2023 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants