Skip to content

Commit 08da451

Browse files
[Typing] Pyrefly: --remove-unused-ignores during pre-commit (#3010)
Hey there 👋 I've noticed that pyrefly can do cleanup of unused ignores with: ```bash pyrefly check --remove-unused-ignores ``` It can be integrated as a part of `pre-commit` step via adding this flag as an arg. > [!Important] > Ensure `pass_filenames: false` is set. > Pyrefly is designed to check the entire project state, and running it only on a subset of staged files can lead to inconsistent results where it "thinks" an ignore is unused because it can't see the rest of the project.
1 parent 7cec166 commit 08da451

35 files changed

Lines changed: 16 additions & 101 deletions

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ repos:
7171
name: Pyrefly (type checking)
7272
pass_filenames: false
7373
language: system
74+
args: ["--remove-unused-ignores"]
7475

7576

7677
- repo: local
7778
hooks:
7879
# Check hyperlinks and external links
7980
- id: lychee-link-checker
8081
name: lychee-link-checker
81-
verbose: true
8282
language: system
8383
require_serial: true
84+
verbose: true
8485
entry: |
8586
/bin/bash -c '
8687
if ! command -v lychee >/dev/null 2>&1; then
@@ -103,6 +104,7 @@ repos:
103104
- "--accept=200,403,429,503"
104105
- "--exclude=http://localhost:.*"
105106
- "--exclude=http://127.0.0.1:.*"
107+
- "--exclude=tcp://localhost:.*"
106108
- "--max-retries=5"
107109
- "--retry-wait-time=10"
108110
- "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"

scripts/checkpoint_conversion/convert_from_hf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def convert_from_hf(input_dir, output_dir, model_name, model_flavor):
2525
model = model_config.build()
2626
model = ModelWrapper(model)
2727

28-
# pyrefly: ignore[bad-instantiation, not-callable]
2928
sd_adapter = model_spec.state_dict_adapter(model_config, None)
3029
assert (
3130
sd_adapter is not None

scripts/checkpoint_conversion/convert_to_hf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def convert_to_hf(
3333
model = model_config.build()
3434
model = ModelWrapper(model)
3535

36-
# pyrefly: ignore[bad-instantiation, not-callable]
3736
sd_adapter = model_spec.state_dict_adapter(model_config, hf_assets_path)
3837
assert (
3938
sd_adapter is not None

scripts/checkpoint_conversion/numerical_tests_qwen3_vl.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ def run_tt(model_flavor, checkpoint_path, tt_inputs, device):
258258

259259
# Replace FlexAttention with SDPA for single-process inference
260260
# (unfused FlexAttention without torch.compile has poor fp16 numerics).
261-
from torchtitan.models.common.attention import (
262-
ScaledDotProductAttention, # pyrefly: ignore [missing-module-attribute]
263-
)
261+
from torchtitan.models.common.attention import ScaledDotProductAttention
264262

265263
for layer in model.layers.values():
266264
layer.attention.attn_backend = "sdpa"

torchtitan/components/tokenizer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,10 @@ def _load_tokenizer_from_path(self, tokenizer_path: str) -> Tokenizer:
235235
tokenizer = Tokenizer(bpe_model)
236236

237237
# Configure GPT-2 style components for proper space handling
238-
# pyrefly: ignore [read-only]
239238
tokenizer.pre_tokenizer = pre_tokenizers.ByteLevel(
240239
add_prefix_space=False
241240
)
242-
# pyrefly: ignore [read-only]
243241
tokenizer.decoder = decoders.ByteLevel()
244-
# pyrefly: ignore [read-only]
245242
tokenizer.post_processor = processors.ByteLevel(trim_offsets=True)
246243

247244
return tokenizer

torchtitan/components/validate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def __init__(
116116
self.tokenizer = tokenizer
117117
self.parallel_dims = parallel_dims
118118
self.loss_fn = loss_fn
119-
# pyrefly: ignore [unexpected-keyword]
120119
self.dl_config = replace(config.dataloader, infinite=config.steps != -1)
121120
self.dp_world_size = dp_world_size
122121
self.dp_rank = dp_rank

torchtitan/config/manager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ def _merge_configs(base, custom) -> type:
161161
DeprecationWarning,
162162
stacklevel=2,
163163
)
164-
# pyrefly: ignore [unknown-name]
165164
result: list[str | tuple[str, Any] | tuple[str, Any, Any]] = []
166165
b_map = {f.name: f for f in fields(base)}
167166
c_map = {f.name: f for f in fields(custom)}
@@ -196,7 +195,6 @@ def _validate_config(self) -> None:
196195
# pyrefly: ignore [missing-attribute]
197196
if not os.path.exists(self.config.hf_assets_path):
198197
logger.warning(
199-
# pyrefly: ignore [missing-attribute]
200198
f"HF assets path {self.config.hf_assets_path} does not exist!"
201199
)
202200
old_tokenizer_path = (
@@ -254,10 +252,8 @@ def list_str_rule(type_info: tyro.constructors.PrimitiveTypeInfo):
254252

255253
try:
256254

257-
# pyrefly: ignore[missing-import]
258255
from rich import print as rprint
259256

260-
# pyrefly: ignore[missing-import]
261257
from rich.pretty import Pretty
262258

263259
config_manager = ConfigManager()

torchtitan/distributed/deepep/deepep.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232

3333
# Global buffer (single buffer per process, recreated if group changes)
34-
# pyrefly: ignore [bad-assignment]
3534
_buffer: Buffer = None
3635

3736
# Global cache for dispatch handles, keyed by handle_id
@@ -118,7 +117,6 @@ def _dispatch_op_impl(
118117
recv_num_tokens_per_expert = torch.tensor(
119118
recv_num_tokens_per_expert_list, dtype=torch.int32, device="cpu"
120119
)
121-
# pyrefly: ignore [bad-return]
122120
return recv_x, recv_indices, recv_scores, recv_num_tokens_per_expert, handle_id
123121

124122

torchtitan/distributed/deepep/hybridep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def _dispatch_impl(
181181
_buffer.group_size,
182182
num_local_experts,
183183
topk_idx.shape[1],
184-
moe_expert_capacity_factor, # pyrefly: ignore [bad-argument-type]
184+
moe_expert_capacity_factor,
185185
pad_multiple=pad_multiple,
186186
)
187187

torchtitan/distributed/parallel_dims.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ def unflatten_mesh(
146146
0,
147147
dim_degrees,
148148
dim_names,
149-
# pyrefly: ignore [bad-argument-type]
150149
backend_override=backend_override,
151150
)
152151

0 commit comments

Comments
 (0)