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

fix: fix mypy errors in rest.py #1599

Merged
merged 9 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ jobs:
python -m pip install nox
- name: Run blacken and lint on the generated output.
run: |
nox -f tests/integration/goldens/asset/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/credentials/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/eventarc/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/logging/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/redis/noxfile.py -s blacken lint_setup_py lint
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
style-check:
runs-on: ubuntu-latest
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from google.api_core import operations_v1
from requests import __version__ as requests_version
import dataclasses
import re
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
import warnings

try:
Expand Down Expand Up @@ -269,7 +269,7 @@ class {{service.name}}RestTransport({{service.name}}Transport):

{% if not method.client_streaming %}
{% if method.input.required_fields %}
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the whole purpose of typing is to provide type hints, then isn't the use of Any defeating the purpose? Is there a more narrow type hint we could provide? (I see that the error message in [1] expects as the map value the type "Dict[<nothing>, <nothing>]")

[1] https://github.com/googleapis/python-bigtable/actions/runs/4196460916/jobs/7277462654

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed Any . PTAL

{% for req_field in method.input.required_fields if req_field.name in method.query_params %}
"{{ req_field.name | camel_case }}" : {% if req_field.field_pb.type == 9 %}"{{req_field.field_pb.default_value }}"{% elif req_field.field_pb.type in [11, 14] %}{}{% else %}{{ req_field.type.python_type(req_field.field_pb.default_value or 0) }}{% endif %},{# default is str #}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{% if proto.messages|length or proto.all_enums|length %}
from typing import MutableMapping, MutableSequence

import proto{% if p != 'proto' %} as {{ p }}{% endif %} # type: ignore
{% endif %}
import proto{% if p != 'proto' %} as {{ p }}{% endif %} # type: ignore

{% filter sort_lines %}
{% for import_ in proto.python_modules %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ from google.longrunning import operations_pb2
from requests import __version__ as requests_version
import dataclasses
import re
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
import warnings

try:
Expand Down Expand Up @@ -299,7 +299,7 @@ class {{service.name}}RestTransport({{service.name}}Transport):

{% if not method.client_streaming %}
{% if method.input.required_fields %}
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
{% for req_field in method.input.required_fields if req_field.name in method.query_params %}
"{{ req_field.name | camel_case }}" : {% if req_field.field_pb.type == 9 %}"{{req_field.field_pb.default_value }}"{% elif req_field.field_pb.type in [11, 14] %}{}{% else %}{{ req_field.type.python_type(req_field.field_pb.default_value or 0) }}{% endif %},{# default is str #}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{% if proto.messages|length or proto.all_enums|length %}
from typing import MutableMapping, MutableSequence

import proto{% if p != 'proto' %} as {{ p }}{% endif %} # type: ignore
{% endif %}
import proto{% if p != 'proto' %} as {{ p }}{% endif %} # type: ignore

{% filter sort_lines %}
{% for import_ in proto.python_modules %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from requests import __version__ as requests_version
import dataclasses
import re
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
import warnings

try:
Expand Down Expand Up @@ -481,7 +481,7 @@ class _AnalyzeIamPolicy(AssetServiceRestStub):
def __hash__(self):
return hash("AnalyzeIamPolicy")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
"analysisQuery" : {}, }

@classmethod
Expand Down Expand Up @@ -561,7 +561,7 @@ class _AnalyzeIamPolicyLongrunning(AssetServiceRestStub):
def __hash__(self):
return hash("AnalyzeIamPolicyLongrunning")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -650,7 +650,7 @@ class _BatchGetAssetsHistory(AssetServiceRestStub):
def __hash__(self):
return hash("BatchGetAssetsHistory")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -726,7 +726,7 @@ class _CreateFeed(AssetServiceRestStub):
def __hash__(self):
return hash("CreateFeed")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -818,7 +818,7 @@ class _DeleteFeed(AssetServiceRestStub):
def __hash__(self):
return hash("DeleteFeed")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -882,7 +882,7 @@ class _ExportAssets(AssetServiceRestStub):
def __hash__(self):
return hash("ExportAssets")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -968,7 +968,7 @@ class _GetFeed(AssetServiceRestStub):
def __hash__(self):
return hash("GetFeed")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -1051,7 +1051,7 @@ class _ListAssets(AssetServiceRestStub):
def __hash__(self):
return hash("ListAssets")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -1127,7 +1127,7 @@ class _ListFeeds(AssetServiceRestStub):
def __hash__(self):
return hash("ListFeeds")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -1203,7 +1203,7 @@ class _SearchAllIamPolicies(AssetServiceRestStub):
def __hash__(self):
return hash("SearchAllIamPolicies")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -1279,7 +1279,7 @@ class _SearchAllResources(AssetServiceRestStub):
def __hash__(self):
return hash("SearchAllResources")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -1355,7 +1355,7 @@ class _UpdateFeed(AssetServiceRestStub):
def __hash__(self):
return hash("UpdateFeed")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from requests import __version__ as requests_version
import dataclasses
import re
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
import warnings

try:
Expand Down Expand Up @@ -281,7 +281,7 @@ class _GenerateAccessToken(IAMCredentialsRestStub):
def __hash__(self):
return hash("GenerateAccessToken")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -366,7 +366,7 @@ class _GenerateIdToken(IAMCredentialsRestStub):
def __hash__(self):
return hash("GenerateIdToken")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -451,7 +451,7 @@ class _SignBlob(IAMCredentialsRestStub):
def __hash__(self):
return hash("SignBlob")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -536,7 +536,7 @@ class _SignJwt(IAMCredentialsRestStub):
def __hash__(self):
return hash("SignJwt")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import proto # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from requests import __version__ as requests_version
import dataclasses
import re
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
import warnings

try:
Expand Down Expand Up @@ -327,7 +327,7 @@ class _CreateTrigger(EventarcRestStub):
def __hash__(self):
return hash("CreateTrigger")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
"triggerId" : "", "validateOnly" : False, }

@classmethod
Expand Down Expand Up @@ -415,7 +415,7 @@ class _DeleteTrigger(EventarcRestStub):
def __hash__(self):
return hash("DeleteTrigger")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
"validateOnly" : False, }

@classmethod
Expand Down Expand Up @@ -494,7 +494,7 @@ class _GetTrigger(EventarcRestStub):
def __hash__(self):
return hash("GetTrigger")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -574,7 +574,7 @@ class _ListTriggers(EventarcRestStub):
def __hash__(self):
return hash("ListTriggers")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
}

@classmethod
Expand Down Expand Up @@ -654,7 +654,7 @@ class _UpdateTrigger(EventarcRestStub):
def __hash__(self):
return hash("UpdateTrigger")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, str] = {
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
"validateOnly" : False, }

@classmethod
Expand Down
Loading