Skip to content

Conversation

ShaneHarvey
Copy link
Member

@ShaneHarvey ShaneHarvey commented Jul 22, 2022

https://jira.mongodb.org/browse/PYTHON-3366

Changes:

  • Support mypy 0.971 and test with latest version.
  • Fix:
     bson/__init__.py: note: In member "decode" of class "BSON": bson/__init__.py:1311: error: A function returning TypeVar should receive at least one argument containing the same Typevar [type-var] ...ptions: CodecOptions = DEFAULT_CODEC_OPTIONS) -> _DocumentType: # typ... 
return cls(encode(document, check_keys, codec_options))

def decode(self, codec_options: CodecOptions = DEFAULT_CODEC_OPTIONS) -> _DocumentType: # type: ignore[override]
def decode(self, codec_options: "CodecOptions[_DocumentType]" = DEFAULT_CODEC_OPTIONS) -> _DocumentType: # type: ignore[override,assignment]
Copy link
Member Author

Choose a reason for hiding this comment

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

The "assignment" ignore is required to silence this error:

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] 
# server side sockets.
self._callback_data.check_ocsp_endpoint = True
self._ctx.set_ocsp_client_callback(callback=_ocsp_callback, data=self._callback_data)
self._ctx.set_ocsp_client_callback(callback=_ocsp_callback, data=self._callback_data) # type: ignore[arg-type]
Copy link
Member Author

Choose a reason for hiding this comment

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

This ignore is required until python/typeshed#8371 is fixed and released.

@ShaneHarvey
Copy link
Member Author

ShaneHarvey commented Jul 22, 2022

The remaining errors are in the tests and look like:

test/test_bson.py: note: In member "assertInvalid" of class "TestBSON": test/test_bson.py:120: error: Argument 2 to "assertRaises" of "TestCase" has incompatible type "Callable[[Union[bytes, memoryview, mmap, array[Any]], Optional[CodecOptions[_DocumentType]]], _DocumentType]"; expected "Callable[..., object]" [arg-type] self.assertRaises(InvalidBSON, decode, data) ^ 

Looks like a mypy bug. I'm not sure why it considers these types are incompatible. Perhaps "_DocumentType" is incompatible with "object"?

I believe this is a typeshed bug that will be fixed by: python/typeshed#8373

Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

LGTM!

@ShaneHarvey ShaneHarvey merged commit 864812d into mongodb:master Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants