Skip to content

Commit bd2b481

Browse files
committed
add alternative typecheckers; add type-simplejson; some annotations and ignores in session.py
1 parent 5e539fe commit bd2b481

File tree

5 files changed

+107
-5
lines changed

5 files changed

+107
-5
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ Live at https://tenantfirstaid.com/
5757
```sh
5858
% make typecheck
5959
```
60+
61+
*typecheck* with other Python typecheckers which are not protected in [PR Checks](.github/workflows/pr-check.yml) - useful for completeness & a 2nd opinion
62+
1. *typecheck* Python code with `mypy`
63+
```sh
64+
% uv run mypy -p tenantfirstaid --python-executable .venv/bin/python3 --check-untyped-defs
65+
```
66+
or
67+
```sh
68+
% make typecheck-mypy
69+
```
70+
1. *typecheck* Python code with `pyrefly`
71+
```sh
72+
% uv run pyrefly check --python-interpreter .venv/bin/python3
73+
```
74+
or
75+
```sh
76+
% make typecheck-pyrefly
77+
```
6078
1. *test* Python code with `pytest`
6179
```sh
6280
% uv run pytest

backend/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ lint: uv.lock
2020
typecheck: uv.lock
2121
$(PYTHON) run ty check $(TYPECHECK_OPTIONS)
2222

23+
typecheck-mypy: uv.lock
24+
$(PYTHON) run mypy $(TYPECHECK_OPTIONS) -p tenantfirstaid --python-executable .venv/bin/python3 --check-untyped-defs
25+
26+
typecheck-pyrefly: uv.lock
27+
$(PYTHON) run pyrefly check $(TYPECHECK_OPTIONS) --python-interpreter .venv/bin/python3
28+
2329
test: uv.lock
2430
uv run pytest -v -s $(TEST_OPTIONS)
2531

backend/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ build-backend = "setuptools.build_meta"
2424
[dependency-groups]
2525
dev = [
2626
"ipdb>=0.13.13",
27+
"mypy>=1.16.1",
28+
"pyrefly>=0.21.0",
2729
"pytest>=8.4.0",
2830
"pytest-cov>=6.1.1",
2931
"pytest-mock>=3.14.1",
3032
"ruff>=0.12.0",
3133
"ty>=0.0.1a11",
3234
"types-Flask>=1.1.6",
35+
"types-simplejson>=3.20.0.20250326",
3336
]
3437

3538
gen_convo = [

backend/tenantfirstaid/session.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ def save_session(response):
5858
def get(self) -> TenantSessionData:
5959
session_id = self.get_flask_session_id()
6060

61-
saved_session = self.db_con.get(session_id)
61+
saved_session: Optional[str] = self.db_con.get(session_id) # type: ignore # known issue https://github.com/valkey-io/valkey-py/issues/164
6262
if not saved_session:
6363
return self.getNewSessionData()
6464

65-
return json.loads(saved_session)
65+
return json.loads(s=saved_session)
6666

6767
def set(self, value: TenantSessionData):
6868
session_id = self.get_flask_session_id()
@@ -79,10 +79,10 @@ def __init__(self, tenant_session: TenantSession):
7979

8080
def dispatch_request(self):
8181
data: Dict[str, Any] = request.json
82-
session_id = self.tenant_session.get_flask_session_id()
82+
session_id: Optional[str] = self.tenant_session.get_flask_session_id()
8383

84-
city = data["city"] or "null"
85-
state = data["state"]
84+
city: str | Literal["null"] = data["city"] or "null"
85+
state: str = data["state"]
8686

8787
# Initialize the session with city and state
8888
initial_data = TenantSessionData(city=city, state=state, messages=[])

backend/uv.lock

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)