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

Intellisense highlights multiple PyMongo methods because of CodecOptions

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.4
    • Affects Version/s: 4.3.3
    • Component/s: Typing
    • None

      Using Visual Studio 2022, Python 3.10, highlights most of PyMongo functions with red lines in strict syntax mode. Switching to the basic syntax hides a lot of issues.

      In Visual Studio go to Tools > Options > Python > Analysys and select Strict in Type checking.

      Make sure Python 3.10 (64-bit) is selected in the drop-down for the current Python environment, if more than one is available.

      import pymongo
      def main():
          mongo_client = pymongo.MongoClient("localhost:27017")
          db = mongo_client.get_database("test_db")
          col = db.get_collection("py_test")
          col.insert_one({"abc": 123})
      
      if __name__ == "__main__":
          main() 
      

      Wait for IntelliSense to kick in (you may need to open just this folder with this file). You will see that all Mongo calls are highlighted with error squiggly lines.

      If you hove over the errors, it will report errors like

      Type of "get_collection" is partially unknown

      Hovering over the highlighted method shows CodeOptions[Unknown], which seems to be what is triggering it. MongoClient error is slightly different, but of similar nature (document_class is Unknown).

      I cannot attach a screenshot in this version of Jira (I could before). I will try to attach a screenshot in a comment.

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            cis74633@bell.net Andre M
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: