Skip to content
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

PYTHON-3679 Support mypy 1.2 #1194

Merged
merged 1 commit into from
Apr 28, 2023
Merged

Conversation

ShaneHarvey
Copy link
Member

@ShaneHarvey ShaneHarvey commented Apr 22, 2023

@ShaneHarvey
Copy link
Member Author

Not quite sure what's going on here but the mypy checks pass locally with 1.2:

$ mypy --install-types --non-interactive bson gridfs tools pymongo
Success: no issues found in 84 source files
$ mypy --install-types --non-interactive bson/codec_options.py     
Success: no issues found in 1 source file

Same versions of python and mypy fail in Actions:

mypy --install-types --non-interactive bson gridfs tools pymongo
  # Test overshadowed codec_options.py file
  mypy --install-types --non-interactive bson/codec_options.py
  mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude "test/mypy_fails/*.*" test
  python -m pip install -U typing_extensions
  mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/[3](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:3).10.11/x6[4](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:4)
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.11/x64/lib
Collecting types-pyOpenSSL
  Downloading types_pyOpenSSL-23.1.0.2-py3-none-any.whl (6.9 kB)
Collecting types-requests
  Downloading types_requests-2.28.11.17-py3-none-any.whl (14 kB)
Requirement already satisfied: cryptography>=3[5](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:5).0.0 in /opt/hostedtoolcache/Python/3.10.11/x[6](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:6)4/lib/python3.10/site-packages (from types-pyOpenSSL) (40.0.2)
Collecting types-urllib3<1.2[7](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:7) (from types-requests)
  Downloading types_urllib3-1.26.25.10-py3-none-any.whl (15 kB)
Requirement already satisfied: cffi>=1.12 in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages (from cryptography>=35.0.0->types-pyOpenSSL) (1.15.1)
Requirement already satisfied: pycparser in /opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages (from cffi>=1.12->cryptography>=35.0.0->types-pyOpenSSL) (2.21)
Installing collected packages: types-urllib3, types-requests, types-pyOpenSSL
Successfully installed types-pyOpenSSL-23.1.0.2 types-requests-2.2[8](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:8).11.17 types-urllib3-1.26.25.10
Installing missing stub packages:
/opt/hostedtoolcache/Python/3.10.11/x64/bin/python -m pip install types-pyOpenSSL types-requests


Success: no issues found in 84 source files
bson/__init__.py: note: In function "_get_object":
Found 13 errors in 1 file (checked 1 source file)
bson/__init__.py:302: error: Too many arguments for "Mapping"  [call-arg]
            return (opts.document_class(data[position : end + 1], opts), p...
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/__init__.py: note: In function "_bson_to_dict":
bson/__init__.py:5[9](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:9)9: error: Too many arguments for "Mapping"  [call-arg]
                return opts.document_class(data, opts)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/__init__.py: note: In function "decode":
bson/__init__.py:[10](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:10)19: error: "CodecOptions" expects no type arguments, but 1
given  [type-arg]
        data: "_ReadableBuffer", codec_options: "Optional[CodecOptions[_Do...
                                                ^
bson/__init__.py:1020: error: A function returning TypeVar should receive at
least one argument containing the same TypeVar  [type-var]
    ) -> "_DocumentType":
         ^
bson/__init__.py:1020: note: Consider using the upper bound "Mapping[str, Any]" instead
bson/__init__.py: note: In function "_decode_all":
bson/__init__.py:1054: error: "CodecOptions" expects no type arguments, but 1
given  [type-arg]
        data: "_ReadableBuffer", opts: "CodecOptions[_DocumentType]"
                                       ^
bson/__init__.py: note: In function "decode_all":
bson/__init__.py:1090: error: "CodecOptions" expects no type arguments, but 1
given  [type-arg]
        data: "_ReadableBuffer", codec_options: "Optional[CodecOptions[_Do...
                                                ^
bson/__init__.py: note: At top level:
bson/__init__.py:[11](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:11)18: error: Unused "type: ignore" comment
        return _decode_all(data, opts)  # type: ignore[arg-type]
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/__init__.py: note: In function "_decode_all_selective":
bson/__init__.py:[12](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:13)12: error: "CodecOptions" expects no type arguments, but 1
given  [type-arg]
        internal_codec_options: CodecOptions[RawBSONDocument] = codec_opti...
                                ^
bson/__init__.py: note: In function "decode_iter":
bson/__init__.py:1226: error: "CodecOptions" expects no type arguments, but 1
given  [type-arg]
        data: bytes, codec_options: "Optional[CodecOptions[_DocumentType]]...
                                    ^
bson/__init__.py: note: In function "decode_file_iter":
bson/__init__.py:1262: error: "CodecOptions" expects no type arguments, but 1
given  [type-arg]
    ...   file_obj: Union[BinaryIO, IO], codec_options: "Optional[CodecOption...
                                                        ^
bson/__init__.py: note: At top level:
bson/__init__.py:[13](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:14)51: error: Unused "type: ignore[assignment]" comment
        def decode(self, codec_options: "CodecOptions[_DocumentType]" = DE...
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
bson/__init__.py: note: In member "decode" of class "BSON":
bson/__init__.py:1[35](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:36)1: error: "CodecOptions" expects no type arguments, but 1
given  [type-arg]
        def decode(self, codec_options: "CodecOptions[_DocumentType]" = DE...
                                        ^
bson/__init__.py:1351: note: Error code "type-arg" not covered by "type: ignore" comment
bson/__init__.py:1351: error: A function returning TypeVar should receive at
least one argument containing the same TypeVar  [type-var]
    ...ions[_DocumentType]" = DEFAULT_CODEC_OPTIONS) -> "_DocumentType":  # t...
                                                        ^
bson/__init__.py:13[51](https://github.com/mongodb/mongo-python-driver/actions/runs/4775556500/jobs/8489944286?pr=1194#step:5:52): note: Error code "type-var" not covered by "type: ignore" comment
bson/__init__.py:1351: note: Consider using the upper bound "Mapping[str, Any]" instead
bson/__init__.py:1351: note: Error code "misc" not covered by "type: ignore" comment
Error: Process completed with exit code 1.

@blink1073
Copy link
Member

I think one of the dependencies updated, since I saw similar errors in #1195

@ShaneHarvey
Copy link
Member Author

On Actions:

Successfully installed mypy-1.2.0 mypy-extensions-1.0.0 pip-23.1.1 tomli-2.0.1 typing-extensions-4.5.0

Locally:

python -m pip list | grep -E 'mypy|typing'                                      
mypy                          1.2.0
mypy-extensions               1.0.0
typing_extensions             4.5.0

Both using Python 3.10.11.

@ShaneHarvey
Copy link
Member Author

Interestingly when I remove bson/codec_options.pyi, I get many of the same errors as above:

$ rm bson/codec_options.pyi && mypy --install-types --non-interactive bson gridfs tools 
bson/__init__.py: note: In function "_get_object":
bson/__init__.py:302: error: Too many arguments for "Mapping"  [call-arg]
            return (opts.document_class(data[position : end + 1], opts), position + obj_size)
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/__init__.py: note: In function "_bson_to_dict":
bson/__init__.py:599: error: Too many arguments for "Mapping"  [call-arg]
                return opts.document_class(data, opts)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bson/__init__.py: note: In function "decode":
bson/__init__.py:1019: error: "CodecOptions" expects no type arguments, but 1 given  [type-arg]
        data: "_ReadableBuffer", codec_options: "Optional[CodecOptions[_DocumentType]]" = None
                                                ^
bson/__init__.py:1020: error: A function returning TypeVar should receive at least one argument containing the same TypeVar  [type-var]
    ) -> "_DocumentType":
         ^
bson/__init__.py:1020: note: Consider using the upper bound "Mapping[str, Any]" instead
....

@ShaneHarvey ShaneHarvey marked this pull request as ready for review April 27, 2023 21:28
@ShaneHarvey
Copy link
Member Author

I'm going to open a new issue to track the CodecOptions issues.

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!

PYTHON-3679 Fix Unused "type: ignore" comment

PYTHON-3679 Fix bson/decimal128.py:103: error: Unsupported operand types for + ("Literal['n']"

PYTHON-3679 Ignore bson/son.py:69: error: Value of type variable "Self" of "__new__" of "dict" cannot be "SON[_Key, _Value]"  [type-var]

PYTHON-3679 More fixes

PYTHON-3679 Change cast to type: ignore

PYTHON-3679 Remove unused import
@ShaneHarvey ShaneHarvey merged commit bc9029a into mongodb:master Apr 28, 2023
@ShaneHarvey ShaneHarvey deleted the PYTHON-3679 branch April 28, 2023 21:28
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