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

Upgrade to latest version of mypy

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.3
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      In PYTHON-3243 we pinned testing to mypy 0.942 temporarily. We should revert that change. The latest version of mypy (0.971) catches at least one bug in our type hints:

      $ mypy --version
      mypy 0.971 (compiled: yes)
      $ mypy --install-types --non-interactive bson gridfs tools pymongo
      bson/__init__.py:64: error: Unused "type: ignore" comment
          from codecs import utf_8_decode as _utf_8_decode  # type: ignore[attr-defined]
          ^
      bson/__init__.py:65: error: Unused "type: ignore" comment
          from codecs import utf_8_encode as _utf_8_encode  # type: ignore[attr-defined]
          ^
      bson/__init__.py: note: In function "_make_c_string_check":
      bson/__init__.py:624: error: Redundant cast to "bytes"  [redundant-cast]
                  return cast(bytes, _utf_8_encode(string)[0]) + b"\x00"
                         ^
      bson/__init__.py: note: In function "_make_c_string":
      bson/__init__.py:636: error: Redundant cast to "bytes"  [redundant-cast]
                  return cast(bytes, _utf_8_encode(string)[0]) + b"\x00"
                         ^
      bson/__init__.py: note: In function "_make_name":
      bson/__init__.py:644: error: Redundant cast to "bytes"  [redundant-cast]
              return cast(bytes, _utf_8_encode(string)[0]) + b"\x00"
                     ^
      bson/__init__.py: note: In member "decode" of class "BSON":
      bson/__init__.py:1311: error: Incompatible default for argument "codec_options" (default has type "CodecOptions[MutableMapping[str, Any]]", argument
      has type "CodecOptions[_DocumentType]")  [assignment]
              def decode(self, codec_options: CodecOptions[_DocumentType] = DEFAULT_CODEC_OPTIONS) -> _DocumentType:  # type: ignore[override]
                                                                            ^
      bson/__init__.py:1311: note: Error code "assignment" not covered by "type: ignore" comment
      pymongo/pyopenssl_context.py: note: In member "__init__" of class "SSLContext":
      pymongo/pyopenssl_context.py:195: error: Argument "data" to "set_ocsp_client_callback" of "Context" has incompatible type "_CallbackData"; expected
      "Optional[bytes]"  [arg-type]
                  self._ctx.set_ocsp_client_callback(callback=_ocsp_callback, data=self._callback_data)
                                                                                   ^
      Found 7 errors in 2 files (checked 80 source files)
      

      The pyopenssl issue is actually a bug in types-PyOpenSSL which I've fixed in https://github.com/python/typeshed/pull/8371

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: