Loading...
Loading...
Interactively fix any type checking issues in Python code
npx skill4agent add saaspegasus/django-skills fix-typesuv run mypy .cast()type: ignorecast()# type: ignore# Preferred - documents the expected type
choices = cast(list[tuple[str, str]], field.choices)
# Avoid when cast is possible - just silences the error
choices = list(field.choices) # type: ignore[arg-type]cast()assert# Preferred - proper error handling
if obj.related_field is None:
raise ValueError("Object must have a related field")
result = obj.related_field.some_method()
# Avoid - assertions can be disabled with -O flag
assert obj.related_field is not None
result = obj.related_field.some_method()python -Otype: ignoretype: ignore# Good - explains why the ignore is needed
self.tier = tier # type: ignore[misc] # mypy can't handle Enum tuple values with custom __init__
# Bad - no explanation
self.tier = tier # type: ignore[misc]gettext_lazydjango-stubs-extfrom __future__ import annotations # Must be the first import
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from django_stubs_ext import StrOrPromise
# Then use StrOrPromise in type hints
def my_function(name: StrOrPromise) -> StrOrPromise:
...
class MyData:
title: StrOrPromise
description: StrOrPromisefrom __future__ import annotationsif TYPE_CHECKING:django-stubs-ext