Loading...
Loading...
Migrate a file to use stricter Pyrefly type checking with annotations required for all functions, classes, and attributes.
npx skill4agent add pytorch/pytorch pyrefly-type-coveragepyrefly.tomlpyre-ignore-all-errors# REMOVE lines like these:
# pyre-ignore-all-errors
# pyre-ignore-all-errors[16,21,53,56]
# @lint-ignore-every PYRELINTpyrefly.toml[[sub-config]]
matches = "path/to/your/file.py"
[sub-config.errors]
implicit-import = false
implicit-any = true[[sub-config]]
matches = "path/to/directory/**"
[sub-config.errors]
implicit-import = false
implicit-any = true[[sub-config]]
matches = "path/to/your/file.py"
[sub-config.errors]
implicit-import = false
implicit-any = true
# Uncomment these for stricter checking:
# unannotated-attribute = true
# unannotated-parameter = true
# unannotated-return = truepyrefly check <FILENAME>pyrefly check torch/_dynamo/utils.pyAny# pyrefly: ignore[...]# Before
def process_data(items, callback):
...
# After
from collections.abc import Callable
def process_data(items: list[str], callback: Callable[[str], bool]) -> None:
...# Before
class MyClass:
def __init__(self):
self.value = None
self.items = []
# After
class MyClass:
value: int | None
items: list[str]
def __init__(self) -> None:
self.value = None
self.items = []TypeAliasTypeVarGenericProtocoltyping_extensions
# Optional values
def get_value(key: str) -> int | None: ...
# Union types
def process(value: str | int) -> str: ...
# Dict and List
def transform(data: dict[str, list[int]]) -> list[str]: ...
# Callable
from collections.abc import Callable
def apply(func: Callable[[int, int], int], a: int, b: int) -> int: ...
# TypeVar for generics
from typing_extensions import TypeVar
T = TypeVar('T')
def first(items: list[T]) -> T: ...# pyre-ignore# pyrefly: ignore[attr-defined]
result = getattr(obj, dynamic_name)()# pyre-ignorepyrefly check <FILENAME>from __future__ import annotationsfrom __future__ import annotationstyping_extensionsfrom typing_extensions import TypeAlias, Self, ParamSpecfrom typing import Dict, List, TypeAlias
ConfigType: TypeAlias = Dict[str, List[int]]
def process_config(config: ConfigType) -> None: ...# 1. Open the file and remove pyre-ignore-all-errors
# 2. Add entry to pyrefly.toml
# 3. Check initial errors
pyrefly check torch/my_module.py
# 4. Add annotations iteratively
# 5. Re-check after changes
pyrefly check torch/my_module.py
# 6. Repeat until clean