Skip to content

Refine Site model fields and reorder SiteManager#3134

Open
ahmedasar00 wants to merge 1 commit intotypeddjango:masterfrom
ahmedasar00:fix/site-name-stub
Open

Refine Site model fields and reorder SiteManager#3134
ahmedasar00 wants to merge 1 commit intotypeddjango:masterfrom
ahmedasar00:fix/site-name-stub

Conversation

@ahmedasar00
Copy link
Contributor

@ahmedasar00 ahmedasar00 commented Feb 27, 2026

Changes

  • Removed outdated Any type hints and replaced them with concrete types:
    • django.contrib.sites.models.Site.domainstr
    • django.contrib.sites.models.Site.namestr
    • django.contrib.sites.models.Site.idint
  • Updated SiteManager methods typing for better accuracy.

Notes

  • Moved SiteManager definition after the Site class to avoid potential forward reference issues.


domain = models.CharField(max_length=100)
name = models.CharField(max_length=50)
domain: Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, why do we change a model field to be Any? What is the original error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, why do we change a model field to be Any? What is the original error?

I used Any while debugging a stubtest error, but I agree the concrete types are better.
Should I revert them to str / int ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should change anything here, I'm pretty sure the current state is correctly infered by the mypy plugin

Copy link
Contributor Author

@ahmedasar00 ahmedasar00 Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, I find it useful because it prevents forward references and using str and int helps ensure greater accuracy, although I could be wrong.

@ahmedasar00 ahmedasar00 closed this Mar 2, 2026
@ahmedasar00 ahmedasar00 reopened this Mar 2, 2026
@ahmedasar00 ahmedasar00 changed the title Fix type hints for Site model fields Refine Site model fields and reorder SiteManager Mar 2, 2026
Detailed changes:

- Map Site fields (id, domain, name) to concrete types to fix DeferredAttribute errors.

- Type SITE_CACHE as dict[int | str, Site] for better precision.

- Add missing __str__ method to Site stub.

- Remove resolved Site entries from stubtest allowlist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants