Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3105

Investigate Ways to Make Keyword Arguments Typing Easier

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When the user defines keyword arguments as a variable and then passes it to a constructor, it can trip up mypy. For example:

       kwargs = {'socketTimeoutMS': 100}
       kwargs['retryReads'] = False
      client = MongoClient(self.server.uri, **kwargs)
      

      Gives the error:

      Argument 2 to "MongoClient" has
      incompatible type "**Dict[str, int]"; expected "Type[Any]"  [arg-type]
      

      The deficiency is tracked in https://github.com/python/mypy/issues/8862.

      We could look into offering a TypeDict as a workaround with optional values, so that the user could use code like:

      kwargs: MongoClientOptions = {'socketTimeoutMS': 100}
      kwargs['retryReads'] = False
      client = MongoClient(self.server.uri, **kwargs)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: