Skip to content

Type template attrs on SingletonModelAdmin - #159

Open
vokracko wants to merge 1 commit into
lazybird:masterfrom
vokracko:type-singleton-admin-templates
Open

Type template attrs on SingletonModelAdmin#159
vokracko wants to merge 1 commit into
lazybird:masterfrom
vokracko:type-singleton-admin-templates

Conversation

@vokracko

@vokracko vokracko commented Jul 20, 2026

Copy link
Copy Markdown

object_history_template and change_form_template are the only unannotated attrs on SingletonModelAdmin. Unannotated, mypy infers them as bare str - but ModelAdmin types them ClassVar[_TemplateForResponseT | None] via django-stubs.

Subclass SingletonModelAdmin next to another ModelAdmin subclass that keeps the stub type and the two bases disagree:

error: Definition of "object_history_template" in base class "SingletonModelAdmin" is incompatible with definition in base class "Foo" [misc]

Annotating both to match the base clears it.

`object_history_template` and `change_form_template` are the only unannotated attrs on `SingletonModelAdmin`. Unannotated, mypy infers them as bare `str` - but `ModelAdmin` types them `ClassVar[_TemplateForResponseT | None]` via django-stubs.

Subclass `SingletonModelAdmin` next to another `ModelAdmin` subclass that keeps the stub type and the two bases disagree:

```
error: Definition of "object_history_template" in base class "SingletonModelAdmin" is incompatible with definition in base class "Foo"  [misc]
```

Annotating both to match the base clears it. Runtime unaffected, `from __future__ import annotations` is already on.
@vokracko
vokracko force-pushed the type-singleton-admin-templates branch from 31f42aa to ba102e2 Compare July 20, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant