Skip to content

Commit 5c6eed3

Browse files
authored
build: use pyright as static type checker (#288)
When analyzing overload definitions, Pyright does a better job at understanding the conventions we have established. This is due to how Pyright has decided to interpret PEP-484. Additional details are available here: https://github.com/microsoft/pyright/blob/main/docs/type-concepts-advanced.md#overloads Additionally, Pyright discovered a few issues with types, which are addressed in this change.
1 parent ded77b4 commit 5c6eed3

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build:
1212
clean:
1313
$(MAKE) -C ./docs $@
1414
$(MAKE) -C ./integration $@
15-
rm -rf .coverage .mypy_cache .pytest_cache .ruff_cache *.egg-info build coverage.xml dist htmlcov coverage.xml
15+
rm -rf .coverage .pytest_cache .ruff_cache *.egg-info build coverage.xml dist htmlcov coverage.xml
1616
find src -name "_version.py" -exec rm -rf {} +
1717
find . -name "*.egg-info" -exec rm -rf {} +
1818
find . -name "*.pyc" -exec rm -f {} +
@@ -54,7 +54,7 @@ it:
5454
$(MAKE) -C ./integration
5555

5656
lint:
57-
$(PYTHON) -m mypy --install-types --non-interactive .
57+
$(PYTHON) -m pyright
5858
$(PYTHON) -m ruff check
5959

6060
test:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ dependencies = ["requests>=2.31.0,<3"]
2525
Source = "https://github.com/posit-dev/posit-sdk-py"
2626
Issues = "https://github.com/posit-dev/posit-sdk-py/issues"
2727

28-
[tool.mypy]
29-
exclude = "integration/resources"
28+
[tool.pyright]
29+
include = ["src"]
3030

3131
[tool.pytest.ini_options]
3232
testpaths = ["tests"]

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
build
22
coverage
3-
mypy
43
pandas
54
pre-commit
65
pyjson5
6+
pyright
77
pytest
88
responses
99
rsconnect-python

src/posit/connect/content.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ def update(self, *args, **kwargs) -> None:
195195

196196
@property
197197
def bundles(self) -> Bundles:
198-
return Bundles(self.params, self.guid)
198+
return Bundles(self.params, self["guid"])
199199

200200
@property
201201
def environment_variables(self) -> EnvVars:
202-
return EnvVars(self.params, self.guid)
202+
return EnvVars(self.params, self["guid"])
203203

204204
@property
205205
def permissions(self) -> Permissions:
206-
return Permissions(self.params, self.guid)
206+
return Permissions(self.params, self["guid"])
207207

208208
@property
209209
def owner(self) -> dict:
@@ -213,12 +213,12 @@ def owner(self) -> dict:
213213
# If it's not included, we can retrieve the information by `owner_guid`
214214
from .users import Users
215215

216-
self["owner"] = Users(self.params).get(self.owner_guid)
216+
self["owner"] = Users(self.params).get(self["owner_guid"])
217217
return self["owner"]
218218

219219
@property
220220
def _variants(self) -> Variants:
221-
return Variants(self.params, self.guid)
221+
return Variants(self.params, self["guid"])
222222

223223
@property
224224
def is_interactive(self) -> bool:

src/posit/connect/external/databricks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ def __init__(self, client: Client, user_session_token: str):
3535
self._user_session_token = user_session_token
3636

3737
def __call__(self) -> Dict[str, str]:
38-
access_token = self._client.oauth.get_credentials(
38+
credentials = self._client.oauth.get_credentials(
3939
self._user_session_token
40-
)["access_token"]
40+
)
41+
access_token = credentials.get("access_token")
42+
if access_token is None:
43+
raise ValueError(
44+
"Missing value for field 'access_token' in credentials."
45+
)
4146
return {"Authorization": f"Bearer {access_token}"}
4247

4348

src/posit/connect/external/snowflake.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def token(self) -> Optional[str]:
4040
if self._client is None:
4141
self._client = Client()
4242

43-
access_token = self._client.oauth.get_credentials(
43+
credentials = self._client.oauth.get_credentials(
4444
self._user_session_token
45-
)["access_token"]
46-
return access_token
45+
)
46+
return credentials.get("access_token")

0 commit comments

Comments
 (0)