Skip to content

Commit e22152c

Browse files
Add initial tests for exports and run them in mypy and pyright (#1135)
1 parent 8607f1e commit e22152c

File tree

17 files changed

+151
-22
lines changed

17 files changed

+151
-22
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ on:
1919

2020
jobs:
2121
lint:
22-
name: Lint
22+
name: Lint & Mypy
2323
runs-on: ubuntu-latest
2424
steps:
2525
- uses: actions/checkout@v3
2626
- name: Set up Python 3
2727
uses: actions/setup-python@v4
2828
with:
2929
python-version: "3.10"
30+
- name: mypy
31+
run: make mypy
3032
- name: lint
3133
run: make lint
3234
- name: fmtcheck

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $(VENV_NAME)/bin/activate: setup.py requirements.txt
1010
${VENV_NAME}/bin/python -m pip install -r requirements.txt
1111
@touch $(VENV_NAME)/bin/activate
1212

13-
test: venv pyright lint
13+
test: venv pyright lint mypy
1414
@${VENV_NAME}/bin/tox -p auto -e $(DEFAULT_TEST_ENV) $(TOX_ARGS)
1515

1616
test-nomock: venv
@@ -25,6 +25,9 @@ coveralls: venv
2525
pyright: venv
2626
@${VENV_NAME}/bin/tox -e pyright $(PYRIGHT_ARGS)
2727

28+
mypy: venv
29+
@${VENV_NAME}/bin/tox -e mypy $(MYPY_ARGS)
30+
2831
fmt: venv
2932
@${VENV_NAME}/bin/tox -e fmt
3033

@@ -43,4 +46,4 @@ update-version:
4346

4447
codegen-format: fmt
4548

46-
.PHONY: ci-test clean codegen-format coveralls fmt fmtcheck lint test test-nomock test-travis update-version venv pyright
49+
.PHONY: ci-test clean codegen-format coveralls fmt fmtcheck lint test test-nomock test-travis update-version venv pyright mypy

pyproject.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,24 @@ exclude = '''
2323
)
2424
'''
2525
[tool.pyright]
26-
include = ["stripe", "tests/test_generated_examples.py"]
26+
include = [
27+
"stripe",
28+
"tests/test_generated_examples.py",
29+
"tests/test_exports.py",
30+
]
2731
exclude = ["build", "**/__pycache__"]
2832
reportMissingTypeArgument = true
2933
reportUnnecessaryCast = true
3034
reportUnnecessaryComparison = true
3135
reportUnnecessaryContains = true
3236
reportUnnecessaryIsInstance = true
37+
reportPrivateImportUsage = true
38+
reportUnnecessaryTypeIgnoreComment = true
39+
40+
[tool.mypy]
41+
follow_imports = "silent"
42+
python_version = "3.10"
43+
files = ["tests/test_exports.py"]
44+
disallow_untyped_calls = true
45+
disallow_untyped_defs = true
46+
warn_unused_ignores = true

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ virtualenv<20.22.0
77
pyright == 1.1.336
88
black == 22.8.0
99
flake8
10+
mypy == 1.7.0
1011

1112
-r test-requirements.txt

stripe/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
log: Optional[Literal["debug", "info"]] = None
3939

4040
# API resources
41-
from stripe.api_resources import * # pyright: ignore # noqa
41+
from stripe.api_resources import * # noqa
4242

43-
from stripe.api_resources import abstract # pyright: ignore # noqa
43+
from stripe.api_resources import abstract # noqa
4444

4545
# OAuth
4646
from stripe.oauth import OAuth # noqa

stripe/api_requestor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
self._client = client
102102
elif stripe.default_http_client:
103103
self._client = stripe.default_http_client
104-
if proxy != self._default_proxy: # type: ignore
104+
if proxy != self._default_proxy:
105105
warnings.warn(
106106
"stripe.proxy was updated after sending a "
107107
"request - this is a no-op. To use a different proxy, "

stripe/api_resources/abstract/api_resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def _static_request(
147147

148148
if idempotency_key is not None:
149149
headers = {} if headers is None else headers.copy()
150-
headers.update(util.populate_headers(idempotency_key)) # type: ignore
150+
headers.update(util.populate_headers(idempotency_key))
151151

152152
response, api_key = requestor.request(method_, url_, params, headers)
153153
return util.convert_to_stripe_object(
@@ -186,7 +186,7 @@ def _static_request_stream(
186186

187187
if idempotency_key is not None:
188188
headers = {} if headers is None else headers.copy()
189-
headers.update(util.populate_headers(idempotency_key)) # type: ignore
189+
headers.update(util.populate_headers(idempotency_key))
190190

191191
response, _ = requestor.request_stream(method_, url_, params, headers)
192192
return response

stripe/api_resources/abstract/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def class_url(cls):
4242
)
4343
# Namespaces are separated in object names with periods (.) and in URLs
4444
# with forward slashes (/), so replace the former with the latter.
45-
base = cls._resource_cls.OBJECT_NAME.replace(".", "/") # type: ignore
45+
base = cls._resource_cls.OBJECT_NAME.replace(".", "/")
4646
return "/v1/test_helpers/%ss" % (base,)
4747

4848
def instance_url(self):

stripe/api_resources/list_object.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# pyright: strict
1+
# pyright: strict, reportUnnecessaryTypeIgnoreComment=false
2+
# reportUnnecessaryTypeIgnoreComment is set to false because some type ignores are required in some
3+
# python versions but not the others
24
from typing_extensions import Self
35

46
from typing import (
@@ -115,7 +117,9 @@ def __getitem__(self, k: str) -> T:
115117
# Pyright doesn't like this because ListObject inherits from StripeObject inherits from Dict[str, Any]
116118
# and so it wants the type of __iter__ to agree with __iter__ from Dict[str, Any]
117119
# But we are iterating through "data", which is a List[T].
118-
def __iter__(self) -> Iterator[T]: # pyright: ignore
120+
def __iter__( # pyright: ignore
121+
self,
122+
) -> Iterator[T]:
119123
return getattr(self, "data", []).__iter__()
120124

121125
def __len__(self) -> int:
@@ -132,11 +136,11 @@ def auto_paging_iter(self) -> Iterator[T]:
132136
"ending_before" in self._retrieve_params
133137
and "starting_after" not in self._retrieve_params
134138
):
135-
for item in reversed(page): # type: ignore
139+
for item in reversed(page):
136140
yield item
137141
page = page.previous_page()
138142
else:
139-
for item in page: # type: ignore
143+
for item in page:
140144
yield item
141145
page = page.next_page()
142146

stripe/api_resources/quote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ def pdf(
15671567
...
15681568

15691569
@util.class_method_variant("_cls_pdf")
1570-
def pdf( # type: ignore
1570+
def pdf( # pyright: ignore
15711571
self,
15721572
api_key=None,
15731573
api_version=None,

0 commit comments

Comments
 (0)