Skip to content

PYTHON-3366 Support mypy 0.971 and test with latest version #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 25, 2022

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...
    

@@ -1308,7 +1308,7 @@ def encode(
"""
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]

@@ -192,7 +192,7 @@ def __init__(self, protocol):
# side configuration and wrap_socket tries to support both client and
# 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants