mongo-types icon indicating copy to clipboard operation
mongo-types copied to clipboard

port argument of register_connection() is typed as str | None, but mongoengine expects int

Open edward-petersen-cynn opened this issue 2 years ago • 0 comments

mypy reports that the port argument for the register_connection() function needs to be either a string or None:

Argument "port" to "register_connection" has incompatible type "int"; expected "str | None"  [arg-type]

Which is what the mongoengine-stubs/connection.pyi file dictates. But when I replace it with a string representation of the port number, mongoengine reports the port must be an integer.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/mongoengine/connection.py", line 348, in _create_connection
    return mongo_client_class(**connection_settings)
  File "/usr/local/lib/python3.10/site-packages/pymongo/mongo_client.py", line 715, in __init__
    raise TypeError("port must be an instance of int")
TypeError: port must be an instance of int

According to pymongo on github, the type check on the port has been there for 11 years, so I think this is just an oversight.

edward-petersen-cynn avatar Aug 01 '23 00:08 edward-petersen-cynn