Skip to content

Commit

Permalink
Add no blanket type ignore (#1734)
Browse files Browse the repository at this point in the history
* Add PGH003: Disallowed blanket `type: ignore` annotations.

* Add specific mypy error codes
  • Loading branch information
UnknownPlatypus authored Sep 24, 2023
1 parent e6598f8 commit a539bbe
Show file tree
Hide file tree
Showing 37 changed files with 95 additions and 94 deletions.
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/checks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ...

class InlineModelAdminChecks(BaseModelAdminChecks):
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... # type: ignore
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... # type: ignore[override]

def must_be(type: Any, option: Any, obj: Any, id: Any) -> list[CheckMessage]: ...
def must_inherit_from(parent: Any, option: Any, obj: Any, id: Any) -> list[CheckMessage]: ...
Expand Down
8 changes: 4 additions & 4 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ class InlineModelAdmin(Generic[_ChildModelT, _ParentModelT], BaseModelAdmin[_Chi
self, request: HttpRequest, obj: _ParentModelT | None = ..., **kwargs: Any
) -> type[BaseInlineFormSet[_ChildModelT, _ParentModelT, forms.ModelForm[_ChildModelT]]]: ...
def get_queryset(self, request: HttpRequest) -> QuerySet[_ChildModelT]: ...
def has_add_permission(self, request: HttpRequest, obj: _ParentModelT | None) -> bool: ... # type: ignore
def has_change_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore
def has_delete_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore
def has_view_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore
def has_add_permission(self, request: HttpRequest, obj: _ParentModelT | None) -> bool: ... # type: ignore[override]
def has_change_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore[override]
def has_delete_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore[override]
def has_view_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore[override]

class StackedInline(InlineModelAdmin[_ChildModelT, _ParentModelT]):
template: str
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def lookup_field(
name: Callable | str, obj: Model, model_admin: BaseModelAdmin | None = ...
) -> tuple[Field | None, str | None, Any]: ...
@overload
def label_for_field( # type: ignore
def label_for_field( # type: ignore[misc]
name: Callable | str,
model: type[Model],
model_admin: BaseModelAdmin | None = ...,
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/widgets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ForeignKeyRawIdWidget(forms.TextInput):
def label_and_url_for_value(self, value: Any) -> tuple[str, str]: ...

class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
rel: ManyToManyRel # type: ignore
rel: ManyToManyRel # type: ignore[assignment]
def __init__(
self,
rel: ManyToManyRel,
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/db/backends/mysql/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures):
@property
def empty_intersection_returns_none(self) -> bool: ...
@property
def supports_geometry_field_unique_index(self) -> bool: ... # type: ignore
def supports_geometry_field_unique_index(self) -> bool: ... # type: ignore[override]
@property
def django_test_skips(self) -> dict[str, Any]: ... # type: ignore
def django_test_skips(self) -> dict[str, Any]: ... # type: ignore[override]
8 changes: 4 additions & 4 deletions django-stubs/contrib/gis/db/backends/mysql/operations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
@property
def mariadb(self) -> bool: ...
@property
def mysql(self) -> bool: ... # type: ignore
def mysql(self) -> bool: ... # type: ignore[override]
@property
def select(self) -> str: ... # type: ignore
def select(self) -> str: ... # type: ignore[override]
@property
def from_text(self) -> str: ... # type: ignore
def from_text(self) -> str: ... # type: ignore[override]
@property
def gis_operators(self) -> dict[str, SpatialOperator]: ...
disallowed_aggregates: Any
@property
def unsupported_functions(self) -> set[str]: ... # type: ignore
def unsupported_functions(self) -> set[str]: ... # type: ignore[override]
def geo_db_type(self, f: Any) -> Any: ...
def get_distance(self, f: Any, value: Any, lookup_type: Any) -> list[Any]: ...
def get_geometry_converter(self, expression: Any) -> Callable[[Any, Any, Any], GEOSGeometryBase | None]: ...
2 changes: 1 addition & 1 deletion django-stubs/contrib/postgres/fields/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...
@property
def description(self) -> str: ... # type: ignore
def description(self) -> str: ... # type: ignore[override]
def get_transform(self, name: Any) -> type[Transform] | None: ...
4 changes: 2 additions & 2 deletions django-stubs/contrib/postgres/forms/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SimpleArrayField(forms.CharField):
) -> None: ...
def clean(self, value: Any) -> Sequence[Any]: ...
def prepare_value(self, value: Any) -> Any: ...
def to_python(self, value: Any) -> Sequence[Any]: ... # type: ignore
def to_python(self, value: Any) -> Sequence[Any]: ... # type: ignore[override]
def validate(self, value: Sequence[Any]) -> None: ...
def run_validators(self, value: Sequence[Any]) -> None: ...
def has_changed(self, initial: Any, data: Any) -> bool: ...
Expand All @@ -43,7 +43,7 @@ class SplitArrayWidget(forms.Widget):
def id_for_label(self, id_: str) -> str: ...
def get_context(self, name: str, value: Any, attrs: _OptAttrs | None = ...) -> dict[str, Any]: ...
@property
def needs_multipart_form(self) -> bool: ... # type: ignore
def needs_multipart_form(self) -> bool: ... # type: ignore[override]

class SplitArrayField(forms.Field):
default_error_messages: _ErrorMessagesDict
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/postgres/forms/hstore.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class HStoreField(forms.CharField):
widget: _ClassLevelWidgetT
default_error_messages: _ErrorMessagesDict
def prepare_value(self, value: Any) -> Any: ...
def to_python(self, value: Any) -> dict[str, str | None]: ... # type: ignore
def to_python(self, value: Any) -> dict[str, str | None]: ... # type: ignore[override]
def has_changed(self, initial: Any, data: Any) -> bool: ...
2 changes: 1 addition & 1 deletion django-stubs/contrib/postgres/indexes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from django.utils.datastructures import _ListOrTuple

class PostgresIndex(Index):
@property
def max_name_length(self) -> int: ... # type: ignore
def max_name_length(self) -> int: ... # type: ignore[override]
def create_sql(
self, model: type[Model], schema_editor: BaseDatabaseSchemaEditor, using: str = ..., **kwargs: Any
) -> Statement: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/postgres/search.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SearchQueryCombinable:
def __and__(self, other: SearchQueryCombinable) -> Self: ...
def __rand__(self, other: SearchQueryCombinable) -> Self: ...

class SearchQuery(SearchQueryCombinable, Func): # type: ignore
class SearchQuery(SearchQueryCombinable, Func): # type: ignore[misc]
SEARCH_TYPES: dict[str, str]
def __init__(
self,
Expand All @@ -60,7 +60,7 @@ class SearchQuery(SearchQueryCombinable, Func): # type: ignore
) -> None: ...
def __invert__(self) -> Self: ... # type: ignore[override]

class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: ignore
class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: ignore[misc]
def __init__(
self,
lhs: Combinable,
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/staticfiles/handlers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StaticFilesHandlerMixin:
def get_response(self, request: HttpRequest) -> HttpResponseBase: ...
async def get_response_async(self, request: HttpRequest) -> HttpResponseBase: ...

class StaticFilesHandler(StaticFilesHandlerMixin, WSGIHandler): # type: ignore
class StaticFilesHandler(StaticFilesHandlerMixin, WSGIHandler): # type: ignore[misc]
application: WSGIHandler
base_url: ParseResult
def __init__(self, application: WSGIHandler) -> None: ...
Expand All @@ -36,7 +36,7 @@ class StaticFilesHandler(StaticFilesHandlerMixin, WSGIHandler): # type: ignore
start_response: StartResponse,
) -> HttpResponseBase: ...

class ASGIStaticFilesHandler(StaticFilesHandlerMixin, ASGIHandler): # type: ignore
class ASGIStaticFilesHandler(StaticFilesHandlerMixin, ASGIHandler): # type: ignore[misc]
application: ASGIHandler
base_url: ParseResult
def __init__(self, application: ASGIHandler) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/staticfiles/storage.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ManifestFilesMixin(HashedFilesMixin):
def post_process(self, *args: Any, **kwargs: Any) -> _PostProcessT: ...
def stored_name(self, name: str) -> str: ...

class ManifestStaticFilesStorage(ManifestFilesMixin, StaticFilesStorage): ... # type: ignore
class ManifestStaticFilesStorage(ManifestFilesMixin, StaticFilesStorage): ... # type: ignore[misc]
class ConfiguredStorage(LazyObject): ...

staticfiles_storage: Storage
4 changes: 2 additions & 2 deletions django-stubs/core/handlers/asgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class ASGIRequest(HttpRequest):
META: dict[str, Any]
def __init__(self, scope: Mapping[str, Any], body_file: IO[bytes]) -> None: ...
@property
def GET(self) -> _ImmutableQueryDict: ... # type: ignore
def GET(self) -> _ImmutableQueryDict: ... # type: ignore[override]
POST: _ImmutableQueryDict
FILES: MultiValueDict
@property
def COOKIES(self) -> dict[str, str]: ... # type: ignore
def COOKIES(self) -> dict[str, str]: ... # type: ignore[override]

_T = TypeVar("_T")

Expand Down
6 changes: 3 additions & 3 deletions django-stubs/core/mail/message.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class MIMEMixin:
def as_string(self, unixfrom: bool = ..., linesep: str = ...) -> str: ...
def as_bytes(self, unixfrom: bool = ..., linesep: str = ...) -> bytes: ...

class SafeMIMEMessage(MIMEMixin, MIMEMessage): # type: ignore
class SafeMIMEMessage(MIMEMixin, MIMEMessage): # type: ignore[misc]
defects: list[Any]
epilogue: Any
policy: Policy
preamble: Any
def __setitem__(self, name: str, val: str) -> None: ...

class SafeMIMEText(MIMEMixin, MIMEText): # type: ignore
class SafeMIMEText(MIMEMixin, MIMEText): # type: ignore[misc]
defects: list[Any]
epilogue: None
policy: Policy
Expand All @@ -46,7 +46,7 @@ class SafeMIMEText(MIMEMixin, MIMEText): # type: ignore
self, payload: list[Message] | str | bytes, charset: str | Charset.Charset | None = ...
) -> None: ...

class SafeMIMEMultipart(MIMEMixin, MIMEMultipart): # type: ignore
class SafeMIMEMultipart(MIMEMixin, MIMEMultipart): # type: ignore[misc]
defects: list[Any]
epilogue: None
policy: Policy
Expand Down
36 changes: 18 additions & 18 deletions django-stubs/db/backends/mysql/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,46 +42,46 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_table_check_constraints: bool
can_return_rows_from_bulk_insert: bool
@property
def allows_auto_pk_0(self) -> bool: ... # type: ignore
def allows_auto_pk_0(self) -> bool: ... # type: ignore[override]
@property
def update_can_self_select(self) -> bool: ... # type: ignore
def update_can_self_select(self) -> bool: ... # type: ignore[override]
@property
def can_introspect_foreign_keys(self) -> bool: ... # type: ignore
def can_introspect_foreign_keys(self) -> bool: ... # type: ignore[override]
@property
def introspected_field_types(self) -> dict[str, str]: ... # type: ignore [override]
@property
def can_return_columns_from_insert(self) -> bool: ... # type: ignore
def can_return_columns_from_insert(self) -> bool: ... # type: ignore[override]
@property
def has_zoneinfo_database(self) -> bool: ... # type: ignore
def has_zoneinfo_database(self) -> bool: ... # type: ignore[override]
@property
def is_sql_auto_is_null_enabled(self) -> bool: ...
@property
def supports_over_clause(self) -> bool: ... # type: ignore
def supports_over_clause(self) -> bool: ... # type: ignore[override]
@property
def supports_column_check_constraints(self) -> bool: ... # type: ignore
def supports_column_check_constraints(self) -> bool: ... # type: ignore[override]
@property
def can_introspect_check_constraints(self) -> bool: ... # type: ignore
def can_introspect_check_constraints(self) -> bool: ... # type: ignore[override]
@property
def has_select_for_update_skip_locked(self) -> bool: ... # type: ignore
def has_select_for_update_skip_locked(self) -> bool: ... # type: ignore[override]
@property
def has_select_for_update_nowait(self) -> bool: ... # type: ignore
def has_select_for_update_nowait(self) -> bool: ... # type: ignore[override]
@property
def has_select_for_update_of(self) -> bool: ... # type: ignore
def has_select_for_update_of(self) -> bool: ... # type: ignore[override]
@property
def supports_explain_analyze(self) -> bool: ...
@property
def supported_explain_formats(self) -> set[str]: ... # type: ignore
def supported_explain_formats(self) -> set[str]: ... # type: ignore[override]
@property
def supports_transactions(self) -> bool: ...
@property
def ignores_table_name_case(self) -> bool: ... # type: ignore
def ignores_table_name_case(self) -> bool: ... # type: ignore[override]
@property
def supports_default_in_lead_lag(self) -> bool: ... # type: ignore
def supports_default_in_lead_lag(self) -> bool: ... # type: ignore[override]
@property
def supports_json_field(self) -> bool: ... # type: ignore
def supports_json_field(self) -> bool: ... # type: ignore[override]
@property
def can_introspect_json_field(self) -> bool: ... # type: ignore
def can_introspect_json_field(self) -> bool: ... # type: ignore[override]
@property
def supports_index_column_ordering(self) -> bool: ... # type: ignore
def supports_index_column_ordering(self) -> bool: ... # type: ignore[override]
@property
def supports_expression_indexes(self) -> bool: ... # type: ignore
def supports_expression_indexes(self) -> bool: ... # type: ignore[override]
6 changes: 3 additions & 3 deletions django-stubs/db/backends/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ class CursorDebugWrapper(CursorWrapper):
) -> Generator[None, None, None]: ...

@overload
def typecast_date(s: None | Literal[""]) -> None: ... # type: ignore
def typecast_date(s: None | Literal[""]) -> None: ... # type: ignore[misc]
@overload
def typecast_date(s: str) -> datetime.date: ...
@overload
def typecast_time(s: None | Literal[""]) -> None: ... # type: ignore
def typecast_time(s: None | Literal[""]) -> None: ... # type: ignore[misc]
@overload
def typecast_time(s: str) -> datetime.time: ...
@overload
def typecast_timestamp(s: None | Literal[""]) -> None: ... # type: ignore
def typecast_timestamp(s: None | Literal[""]) -> None: ... # type: ignore[misc]
@overload
def typecast_timestamp(s: str) -> datetime.datetime: ...
def split_identifier(identifier: str) -> tuple[str, str]: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ class BooleanField(Field[_ST, _GT]):
_pyi_lookup_exact_type: bool

class NullBooleanField(BooleanField[_ST, _GT]):
_pyi_private_set_type: bool | Combinable | None # type: ignore
_pyi_private_get_type: bool | None # type: ignore
_pyi_lookup_exact_type: bool | None # type: ignore
_pyi_private_set_type: bool | Combinable | None # type: ignore[assignment]
_pyi_private_get_type: bool | None # type: ignore[assignment]
_pyi_lookup_exact_type: bool | None # type: ignore[assignment]

class IPAddressField(Field[_ST, _GT]):
_pyi_private_set_type: str | Combinable
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/fields/related.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RelatedField(FieldCacheMixin, Field[_ST, _GT]):
rel_class: type[ForeignObjectRel]
swappable: bool
@property
def related_model(self) -> type[Model] | Literal["self"]: ... # type: ignore
def related_model(self) -> type[Model] | Literal["self"]: ... # type: ignore[override]
def get_forward_related_filter(self, obj: Model) -> dict[str, int | UUID]: ...
def get_reverse_related_filter(self, obj: Model) -> Q: ...
@property
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/fields/reverse_related.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class OneToOneRel(ManyToOneRel):
) -> None: ...

class ManyToManyRel(ForeignObjectRel):
field: ManyToManyField # type: ignore
field: ManyToManyField # type: ignore[assignment]
through: type[Model] | None
through_fields: tuple[str, str] | None
db_constraint: bool
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/signals.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ from django.dispatch import Signal
class_prepared: Signal

class ModelSignal(Signal):
def connect( # type: ignore
def connect( # type: ignore[override]
self,
receiver: Callable,
sender: type[Model] | str | None = ...,
weak: bool = ...,
dispatch_uid: str | None = ...,
apps: Apps | None = ...,
) -> None: ...
def disconnect( # type: ignore
def disconnect( # type: ignore[override]
self,
receiver: Callable | None = ...,
sender: type[Model] | str | None = ...,
Expand Down
18 changes: 9 additions & 9 deletions django-stubs/db/models/sql/compiler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ class SQLCompiler:
) -> Iterator[Sequence[Any]]: ...
def has_results(self) -> bool: ...
@overload
def execute_sql( # type: ignore
def execute_sql( # type: ignore[misc]
self, result_type: Literal["cursor"] = ..., chunked_fetch: bool = ..., chunk_size: int = ...
) -> CursorWrapper: ...
@overload
def execute_sql(
self, result_type: Literal["no results"] | None = ..., chunked_fetch: bool = ..., chunk_size: int = ...
) -> None: ...
@overload
def execute_sql( # type: ignore
def execute_sql( # type: ignore[misc]
self, result_type: Literal["single"] = ..., chunked_fetch: bool = ..., chunk_size: int = ...
) -> Iterable[Sequence[Any]] | None: ...
@overload
Expand All @@ -122,8 +122,8 @@ class SQLInsertCompiler(SQLCompiler):
def prepare_value(self, field: Any, value: Any) -> Any: ...
def pre_save_val(self, field: Any, obj: Any) -> Any: ...
def assemble_as_sql(self, fields: Any, value_rows: Any) -> tuple[list[list[str]], list[list[Any]]]: ...
def as_sql(self) -> list[_AsSqlType]: ... # type: ignore
def execute_sql( # type: ignore
def as_sql(self) -> list[_AsSqlType]: ... # type: ignore[override]
def execute_sql( # type: ignore[override]
self, returning_fields: Sequence[str] | None = ...
) -> list[tuple[Any]]: ... # 1-tuple

Expand All @@ -133,18 +133,18 @@ class SQLDeleteCompiler(SQLCompiler):
def single_alias(self) -> bool: ...
@property
def contains_self_reference_subquery(self) -> bool: ...
def as_sql(self) -> _AsSqlType: ... # type: ignore
def as_sql(self) -> _AsSqlType: ... # type: ignore[override]

class SQLUpdateCompiler(SQLCompiler):
query: UpdateQuery
def as_sql(self) -> _AsSqlType: ... # type: ignore
def execute_sql(self, result_type: Literal["cursor", "no results"]) -> int: ... # type: ignore
def pre_sql_setup(self) -> None: ... # type: ignore
def as_sql(self) -> _AsSqlType: ... # type: ignore[override]
def execute_sql(self, result_type: Literal["cursor", "no results"]) -> int: ... # type: ignore[override]
def pre_sql_setup(self) -> None: ... # type: ignore[override]

class SQLAggregateCompiler(SQLCompiler):
query: AggregateQuery
col_count: int
def as_sql(self) -> _AsSqlType: ... # type: ignore
def as_sql(self) -> _AsSqlType: ... # type: ignore[override]

def cursor_iter(
cursor: CursorWrapper, sentinel: Any, col_count: int | None, itersize: int
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/sql/query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Query(BaseExpression):
def bump_prefix(self, outer_query: Query) -> None: ...
def get_initial_alias(self) -> str: ...
def count_active_tables(self) -> int: ...
def resolve_expression(self, query: Query, *args: Any, **kwargs: Any) -> Query: ... # type: ignore
def resolve_expression(self, query: Query, *args: Any, **kwargs: Any) -> Query: ... # type: ignore[override]
def resolve_lookup_value(self, value: Any, can_reuse: set[str] | None, allow_joins: bool) -> Any: ...
def solve_lookup_type(self, lookup: str) -> tuple[Sequence[str], Sequence[str], Expression | Literal[False]]: ...
def build_filter(
Expand Down
Loading

0 comments on commit a539bbe

Please sign in to comment.