8000 Add presubmit for mypy · Issue #517 · googleapis/proto-plus-python · GitHub
[go: up one dir, main page]

Skip to content
Add presubmit for mypy #517
Open
Open
@parthea

Description

@parthea

Add presubmit for mypy to avoid issues with type hints such as #489

As of writing, here is the output of mypy using the following nox session

@nox.session(python="3.10")
def mypy(session):
    """Run type-checking."""
    session.install(".", "mypy", "pytest")
    session.install(
         "types-pytz",
         "types-protobuf",
    )
    session.run("mypy", "proto", "tests")

partheniou@partheniou-vm-3:~/git/proto-plus-python$ nox -s mypy
nox > Running session mypy
nox > Creating virtual environment (virtualenv) using python3.10 in .nox/mypy
nox > python -m pip install . mypy pytest
nox > python -m pip install types-pytz types-protobuf
nox > mypy proto tests
proto/modules.py:19: error: First argument to namedtuple() should be "_ProtoModule", not "ProtoModule"  [name-match]
proto/modules.py:26: error: Incompatible default for argument "marshal" (default has type "None", argument has type "str")  [assignment]
proto/modules.py:26: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/modules.py:26: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/modules.py:26: error: Incompatible default for argument "manifest" (default has type "frozenset[Never]", argument has type "set[str]")  [assignment]
proto/marshal/rules/message.py:23: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/message.py:23: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/message.py:23: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/message.py:25: error: "type" has no attribute "wrap"  [attr-defined]
proto/utils.py:20: error: Skipping analyzing "google._upb": module is installed, but missing library stubs or py.typed marker  [import-untyped]
proto/marshal/rules/stringy_numbers.py:30: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/stringy_numbers.py:30: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/stringy_numbers.py:30: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/bytes.py:35: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/bytes.py:35: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/bytes.py:35: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/fields.py:37: error: Incompatible default for argument "oneof" (default has type "None", argument has type "str")  [assignment]
proto/fields.py:37: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/fields.py:37: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/fields.py:38: error: Incompatible default for argument "json_name" (default has type "None", argument has type "str")  [assignment]
proto/fields.py:38: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/fields.py:38: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/fields.py:122: error: Value of type "None" is not indexable  [index]
proto/fields.py:127: error: Value of type "None" is not indexable  [index]
proto/marshal/compat.py:27: error: Skipping analyzing "google._upb": module is installed, but missing library stubs or py.typed marker  [import-untyped]
proto/marshal/compat.py:32: error: Cannot find implementation or library stub for module named "google.protobuf.pyext"  [import-not-found]
proto/marshal/compat.py:32: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
proto/marshal/compat.py:50: error: Incompatible types in assignment (expression has type "tuple[type[RepeatedCompositeFieldContainer[Any]], Any]", variable has type "tuple[type[RepeatedCompositeFieldContainer[Any]]]")  [assignment]
proto/marshal/compat.py:51: error: Incompatible types in assignment (expression has type "tuple[type[RepeatedScalarFieldContainer[Any]], Any]", variable has type "tuple[type[RepeatedScalarFieldContainer[Any]]]")  [assignment]
proto/marshal/compat.py:54: error: Incompatible types in assignment (expression has type "tuple[type[MessageMap[Any, Any]], Any]", variable has type "tuple[type[MessageMap[Any, Any]]]")  [assignment]
proto/marshal/rules/enums.py:26: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/enums.py:26: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/enums.py:26: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/collections/repeated.py:75: error: Incompatible default for argument "key" (default has type "None", argument has type "str")  [assignment]
proto/marshal/collections/repeated.py:75: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/collections/repeated.py:75: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/_file_info.py:35: error: Need type annotation for "registry" (hint: "registry: dict[<type>, <type>] = ...")  [var-annotated]
proto/marshal/rules/wrappers.py:29: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/wrappers.py:29: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/wrappers.py:29: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/wrappers.py:30: error: "WrapperRule" has no attribute "_proto_type"  [attr-defined]
proto/marshal/rules/struct.py:29: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/struct.py:29: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/struct.py:29: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/struct.py:69: error: Argument "null_value" to "Value" has incompatible type "int"; expected "ValueType | None"  [arg-type]
proto/marshal/rules/struct.py:93: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/struct.py:93: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/struct.py:93: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/struct.py:121: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/struct.py:121: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/struct.py:121: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/field_mask.py:27: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/field_mask.py:27: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/field_mask.py:27: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/dates.py:34: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/dates.py:34: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/dates.py:34: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/rules/dates.py:38: error: Incompatible return value type (got "None", expected "DatetimeWithNanoseconds")  [return-value]
proto/marshal/rules/dates.py:66: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/rules/dates.py:66: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/rules/dates.py:66: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/marshal.py:73: error: Incompatible default for argument "rule" (default has type "None", argument has type "Rule")  [assignment]
proto/marshal/marshal.py:73: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/marshal.py:73: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/marshal.py:178: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/marshal.py:178: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/marshal.py:178: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/marshal/marshal.py:258: error: Need type annotation for "_instances" (hint: "_instances: dict[<type>, <type>] = ...")  [var-annotated]
proto/marshal/marshal.py:290: error: Incompatible default for argument "absent" (default has type "None", argument has type "bool")  [assignment]
proto/marshal/marshal.py:290: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
proto/marshal/marshal.py:290: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
proto/message.py:452: error: Incompatible return value type (got "bool | None", expected "bool")  [return-value]
proto/message.py:510: error: Unexpected keyword argument "including_default_value_fields" for "MessageToJson"  [call-arg]
proto/message.py:597: error: Unexpected keyword argument "including_default_value_fields" for "MessageToDict"  [call-arg]
proto/message.py:597: error: Incompatible return value type (got "dict[str, Any]", expected "Message")  [return-value]
proto/message.py:610: error: Incompatible return value type (got "dict[str, Any]", expected "Message")  [return-value]
proto/message.py:966: error: Incompatible return value type (got "None", expected "type[Message]")  [return-value]
tests/test_marshal_types_struct.py:250: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_marshal_types_struct.py:257: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
tests/test_fields_enum.py:343: error: Skipping analyzing "google.type": module is installed, but missing library stubs or py.typed marker  [import-untyped]
tests/test_fields_bytes.py:81: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Found 41 errors in 17 files (checked 65 source files)
nox > Command mypy proto tests failed with exit code 1
nox > Session mypy failed.
proto/message.py:597: error: Incompatible return value type (got "dict[str, Any]", expected "Message")  [return-value]
proto/message.py:610: error: Incompatible return value type (got "dict[str, Any]", expected "Message")  [return-value]

should be fixed with #516

Once all errors are fixed, we can add the presubmit and prevent regressions

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: processA process-related concern. May include testing, release, or the like.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0