Skip to content

Commit c8de95c

Browse files
committed
feat: Add mypy integration
1 parent 645e07d commit c8de95c

18 files changed

+577
-298
lines changed

.github/workflows/test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
runs-on: ubuntu-latest
3030
strategy:
3131
matrix:
32-
python-version: ["3.7", "3.8", "3.9", "3.10"]
32+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
3333
steps:
3434
- name: Checkout repository
3535
uses: actions/checkout@v3
@@ -44,6 +44,7 @@ jobs:
4444

4545
- name: Run tests
4646
run: |
47+
python3 -m nox --session "mypy-${{ matrix.python-version }}"
4748
python3 -m nox --session "tests-${{ matrix.python-version }}"
4849
python3 -m nox -e distribution
4950
test:

googlemaps/addressvalidation.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,28 @@
1616
#
1717

1818
"""Performs requests to the Google Maps Address Validation API."""
19+
from __future__ import annotations
20+
from typing import TYPE_CHECKING, cast, List, Optional
21+
22+
import requests
23+
1924
from googlemaps import exceptions
25+
from googlemaps.types import DictStrAny
26+
27+
if TYPE_CHECKING:
28+
from googlemaps.client import Client
2029

2130

2231
_ADDRESSVALIDATION_BASE_URL = "https://addressvalidation.googleapis.com"
2332

2433

25-
def _addressvalidation_extract(response):
34+
def _addressvalidation_extract(response: requests.Response) -> DictStrAny:
2635
"""
2736
Mimics the exception handling logic in ``client._get_body``, but
2837
for addressvalidation which uses a different response format.
2938
"""
3039
body = response.json()
31-
return body
40+
return cast(DictStrAny, body)
3241

3342
# if response.status_code in (200, 404):
3443
# return body
@@ -44,7 +53,13 @@ def _addressvalidation_extract(response):
4453
# raise exceptions.ApiError(response.status_code, error)
4554

4655

47-
def addressvalidation(client, addressLines, regionCode=None , locality=None, enableUspsCass=None):
56+
def addressvalidation(
57+
client: Client,
58+
addressLines: List[str],
59+
regionCode: Optional[str] = None,
60+
locality: Optional[str] = None,
61+
enableUspsCass: Optional[bool] = None,
62+
) -> DictStrAny:
4863
"""
4964
The Google Maps Address Validation API returns a verification of an address
5065
See https://developers.google.com/maps/documentation/address-validation/overview
@@ -59,7 +74,7 @@ def addressvalidation(client, addressLines, regionCode=None , locality=None, ena
5974
:type locality: boolean
6075
"""
6176

62-
params = {
77+
params: DictStrAny = {
6378
"address":{
6479
"addressLines": addressLines
6580
}

0 commit comments

Comments
 (0)