Skip to content

Commit 56fc1a4

Browse files
JacobCoffeeclaude
andauthored
feat: migrate from mypy/pyright to ty type checker (#105)
Co-authored-by: Claude <[email protected]>
1 parent 5a436ee commit 56fc1a4

File tree

15 files changed

+128
-276
lines changed

15 files changed

+128
-276
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,47 @@ jobs:
1010
validate:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v5
1414

1515
- name: Install uv
16-
uses: astral-sh/setup-uv@v3
16+
uses: astral-sh/setup-uv@v6
17+
with:
18+
enable-cache: true
1719

1820
- name: Set up Python
19-
run: uv python install 3.12
21+
uses: actions/setup-python@v6
22+
with:
23+
python-version-file: "pyproject.toml"
2024

2125
- name: Create virtual environment
2226
run: uv sync --all-extras --dev
2327

28+
- name: Run ruff lint
29+
uses: astral-sh/ruff-action@v3
30+
31+
- name: Run ruff format check
32+
uses: astral-sh/ruff-action@v3
33+
with:
34+
args: "format --check --diff"
35+
36+
- name: Run ty type checker
37+
uses: JacobCoffee/[email protected]
38+
with:
39+
version: '0.0.1a26'
40+
args: 'check'
41+
2442
- name: Install prek hooks
2543
run: uv run prek install
2644

2745
- name: Load cached prek Dependencies
2846
id: cached-prek-dependencies
29-
uses: actions/cache@v3
47+
uses: actions/cache@v4
3048
with:
3149
path: ~/.cache/prek/
3250
key: prek|${{ env.pythonLocation }}|${{ hashFiles('.prek-config.yaml') }}
3351

34-
- name: Execute prek
35-
run: uv run prek run --show-diff-on-failure --color=always --all-files
52+
- name: Run other prek hooks
53+
run: uv run prek run --show-diff-on-failure --color=always --all-files --hook-stage manual
3654

3755
test:
3856
runs-on: ubuntu-latest
@@ -44,13 +62,17 @@ jobs:
4462
shell: bash
4563
steps:
4664
- name: Check out repository
47-
uses: actions/checkout@v4
65+
uses: actions/checkout@v5
4866

4967
- name: Install uv
50-
uses: astral-sh/setup-uv@v3
68+
uses: astral-sh/setup-uv@v6
69+
with:
70+
enable-cache: true
5171

5272
- name: Set up Python
53-
run: uv python install 3.12
73+
uses: actions/setup-python@v6
74+
with:
75+
python-version-file: "pyproject.toml"
5476

5577
- name: Create virtual environment
5678
run: uv sync --all-extras --dev
@@ -70,13 +92,17 @@ jobs:
7092
runs-on: ubuntu-latest
7193
steps:
7294
- name: Check out repository
73-
uses: actions/checkout@v4
95+
uses: actions/checkout@v5
7496

7597
- name: Install uv
76-
uses: astral-sh/setup-uv@v3
98+
uses: astral-sh/setup-uv@v6
99+
with:
100+
enable-cache: true
77101

78102
- name: Set up Python
79-
run: uv python install 3.12
103+
uses: actions/setup-python@v6
104+
with:
105+
python-version-file: "pyproject.toml"
80106

81107
- name: Create virtual environment
82108
run: uv sync --all-extras --dev

.pre-commit-config.yaml

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -87,62 +87,14 @@ repos:
8787
# polyfactory,
8888
# discord-py,
8989
# ]
90-
- repo: https://github.com/RobertCraigie/pyright-python
91-
rev: v1.1.407
90+
- repo: local
9291
hooks:
93-
- id: pyright
94-
additional_dependencies:
95-
[
96-
advanced_alchemy,
97-
annotated_types,
98-
anyio>=3,
99-
asyncpg,
100-
asyncpg_stubs,
101-
brotli,
102-
click,
103-
cryptography,
104-
fast-query-parsers>=1.0.2,
105-
fsspec,
106-
greenlet,
107-
httpx>=0.22,
108-
httpx_sse,
109-
hypothesis,
110-
jinja2>=3.1.2,
111-
jsbeautifier,
112-
mako>=1.2.4,
113-
msgspec>=0.18.2,
114-
multidict>=6.0.2,
115-
opentelemetry-instrumentation-asgi,
116-
opentelemetry-sdk,
117-
polyfactory>=2.6.3,
118-
prometheus_client,
119-
"pydantic>=2",
120-
pydantic-extra-types,
121-
pydantic-settings,
122-
pytest,
123-
pytest-asyncio,
124-
pytest-cov,
125-
pytest-lazy-fixture,
126-
pytest-mock,
127-
pytest-rerunfailures,
128-
pytest-timeout,
129-
python-dotenv,
130-
pyyaml,
131-
rich-click,
132-
rich>=13.0.0,
133-
structlog,
134-
types-pytest-lazy-fixture,
135-
types-pyyaml,
136-
typing-extensions,
137-
"uvicorn[standard]",
138-
uvloop>=0.18.0,
139-
asyncpg,
140-
"litestar[cli,structlog,standard]",
141-
types-click,
142-
asyncpg-stubs,
143-
polyfactory,
144-
discord-py,
145-
]
92+
- id: ty
93+
name: ty
94+
entry: uvx ty check
95+
language: system
96+
types: [python]
97+
pass_filenames: false
14698
- repo: https://github.com/sphinx-contrib/sphinx-lint
14799
rev: "v1.0.2"
148100
hooks:

.prek-config.yaml

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -87,59 +87,14 @@ repos:
8787
# polyfactory,
8888
# discord-py,
8989
# ]
90-
- repo: https://github.com/RobertCraigie/pyright-python
91-
rev: v1.1.407
90+
- repo: local
9291
hooks:
93-
- id: pyright
94-
additional_dependencies:
95-
[
96-
advanced_alchemy,
97-
annotated_types,
98-
anyio>=3,
99-
asyncpg,
100-
asyncpg-stubs,
101-
brotli,
102-
click,
103-
cryptography,
104-
fast-query-parsers>=1.0.2,
105-
fsspec,
106-
greenlet,
107-
httpx>=0.22,
108-
httpx_sse,
109-
hypothesis,
110-
jinja2>=3.1.2,
111-
jsbeautifier,
112-
mako>=1.2.4,
113-
msgspec>=0.18.2,
114-
multidict>=6.0.2,
115-
opentelemetry-instrumentation-asgi,
116-
opentelemetry-sdk,
117-
polyfactory>=2.6.3,
118-
prometheus_client,
119-
"pydantic>=2",
120-
pydantic-extra-types,
121-
pydantic-settings,
122-
pytest,
123-
pytest-asyncio,
124-
pytest-cov,
125-
pytest-lazy-fixture,
126-
pytest-mock,
127-
pytest-rerunfailures,
128-
pytest-timeout,
129-
python-dotenv,
130-
pyyaml,
131-
rich-click,
132-
rich>=13.0.0,
133-
structlog,
134-
types-pytest-lazy-fixture,
135-
types-pyyaml,
136-
typing-extensions,
137-
"uvicorn[standard]",
138-
uvloop>=0.18.0,
139-
"litestar[cli,structlog,standard]",
140-
types-click,
141-
discord-py,
142-
]
92+
- id: ty
93+
name: ty
94+
entry: uvx ty check
95+
language: system
96+
types: [python]
97+
pass_filenames: false
14398
- repo: https://github.com/sphinx-contrib/sphinx-lint
14499
rev: "v1.0.2"
145100
hooks:

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Guidelines for writing code
3232
----------------------------
3333

3434
- All code should be fully `typed <https://peps.python.org/pep-0484/>`_. This is enforced via
35-
`mypy <https://mypy.readthedocs.io/en/stable/>`_.
35+
`ty <https://github.com/astral-sh/ty>`_.
3636
- All code should be tested. This is enforced via `pytest <https://docs.pytest.org/en/stable/>`_.
3737
- All code should be properly formatted. This is enforced via `black <https://black.readthedocs.io/en/stable/>`_ and `Ruff <https://beta.ruff.rs/docs/>`_.
3838

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ install-frontend: ## Install the frontend dependencies
5353
.PHONY: install-backend
5454
install-backend: ## Install the backend dependencies
5555
@echo "=> Installing backend dependencies"
56-
@$(UV) venv && $(UV) pip install --quiet -U wheel setuptools cython mypy pip
56+
@$(UV) venv && $(UV) pip install --quiet -U wheel setuptools cython pip
5757
@$(UV) sync --all-extras --force-reinstall --dev
5858
@echo "=> Backend dependencies installed"
5959

@@ -106,6 +106,9 @@ ruff-check: ## Runs Ruff without changing files
106106
ruff-noqa: ## Runs Ruff, adding noqa comments to disable warnings
107107
@$(UV) run --no-sync ruff check . --add-noqa
108108

109+
type-check: ## Run ty type checker
110+
@$(UV) run --no-sync ty check
111+
109112
test: ## Run the tests
110113
@$(UV) run --no-sync pytest tests
111114

@@ -176,7 +179,6 @@ clean: ## Autogenerated File Cleanup
176179
@rm -rf .pytest_cache
177180
@rm -rf tests/.pytest_cache
178181
@rm -rf tests/**/.pytest_cache
179-
@rm -rf .mypy_cache
180182
$(MAKE) docs-clean
181183

182184
destroy: ## Destroy the virtual environment

byte_bot/byte/plugins/custom/litestar.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import datetime
6-
from typing import Self
76

87
from dateutil.zoneinfo import gettz
98
from discord import Embed, EntityType, Interaction, Message, Object, PrivacyLevel
@@ -26,21 +25,21 @@
2625
class GitHubIssue(Modal, title="Create GitHub Issue"):
2726
"""Modal for GitHub issue creation."""
2827

29-
title_ = TextInput[Self](label="title", placeholder="Title")
30-
description = TextInput[Self](
28+
title_ = TextInput(label="title", placeholder="Title")
29+
description = TextInput(
3130
label="Description",
3231
style=TextStyle.paragraph,
3332
placeholder="Please enter an description of the bug you are encountering.",
3433
)
35-
mcve = TextInput[Self](
34+
mcve = TextInput(
3635
label="MCVE",
3736
style=TextStyle.paragraph,
3837
placeholder="Please provide a minimal, complete, and verifiable example of the issue.",
3938
)
40-
logs = TextInput[Self](
39+
logs = TextInput(
4140
label="Logs", style=TextStyle.paragraph, placeholder="Please copy and paste any relevant log output."
4241
)
43-
version = TextInput[Self](
42+
version = TextInput(
4443
label="Litestar Version", placeholder="What version of Litestar are you using when encountering this issue?"
4544
)
4645

@@ -180,6 +179,10 @@ async def schedule_office_hours(self, interaction: Interaction, delay: int | Non
180179
interaction: Interaction object.
181180
delay: Optional. Number of weeks to delay the event.
182181
"""
182+
if interaction.guild is None:
183+
await interaction.response.send_message("This command can only be used in a guild.", ephemeral=True)
184+
return
185+
183186
now_cst = datetime.datetime.now(gettz("America/Chicago"))
184187
start_dt, end_dt = get_next_friday(now_cst, delay)
185188
existing_events = interaction.guild.scheduled_events

byte_bot/byte/plugins/github.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
from typing import Self
6-
75
from discord import Interaction, Message, TextStyle, app_commands
86
from discord.ext.commands import Bot, Cog
97
from discord.ui import Modal, TextInput
@@ -18,21 +16,21 @@
1816
class GitHubIssue(Modal, title="Create GitHub Issue"):
1917
"""Modal for GitHub issue creation."""
2018

21-
title_ = TextInput[Self](label="title", placeholder="Title")
22-
description = TextInput[Self](
19+
title_ = TextInput(label="title", placeholder="Title")
20+
description = TextInput(
2321
label="Description",
2422
style=TextStyle.paragraph,
2523
placeholder="Please enter an description of the bug you are encountering.",
2624
)
27-
mcve = TextInput[Self](
25+
mcve = TextInput(
2826
label="MCVE",
2927
style=TextStyle.paragraph,
3028
placeholder="Please provide a minimal, complete, and verifiable example of the issue.",
3129
)
32-
logs = TextInput[Self](
30+
logs = TextInput(
3331
label="Logs", style=TextStyle.paragraph, placeholder="Please copy and paste any relevant log output."
3432
)
35-
version = TextInput[Self](
33+
version = TextInput(
3634
label="Project Version", placeholder="What version of the project are you using when encountering this issue?"
3735
)
3836

byte_bot/byte/views/abstract_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def delete_button_callback(self, interaction: Interaction) -> None:
7474
Args:
7575
interaction: Interaction object.
7676
"""
77-
if await self.delete_interaction_check(interaction):
77+
if await self.delete_interaction_check(interaction) and interaction.message is not None:
7878
await interaction.message.delete()
7979

8080
async def learn_more_button_callback(self, interaction: Interaction) -> None:

byte_bot/byte/views/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ async def callback(self, interaction: Interaction) -> None:
2929
interaction: Interaction object.
3030
"""
3131
await interaction.response.send_message("Configuration complete!", ephemeral=True)
32-
self.view.stop()
32+
if self.view is not None:
33+
self.view.stop()
3334

3435

3536
class BackButton(Button):
@@ -63,7 +64,8 @@ async def callback(self, interaction: Interaction) -> None:
6364
interaction: Interaction object.
6465
"""
6566
await interaction.response.send_message("Configuration cancelled.", ephemeral=True)
66-
self.view.stop()
67+
if self.view is not None:
68+
self.view.stop()
6769

6870

6971
class ConfigSelect(Select):

0 commit comments

Comments
 (0)