Skip to content

Conversation

JohananOppongAmoateng
Copy link
Contributor

Description

This PR adds type hints to the middleware and toolbar modules. It's based on the work of @leandrodesouzadev in this pr #1848

Fixes #1705

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

@JohananOppongAmoateng
Copy link
Contributor Author

@tim-schilling @matthiask I suggest we start using https://github.com/typeddjango/django-stubs for the typing

@JohananOppongAmoateng JohananOppongAmoateng marked this pull request as ready for review October 13, 2025 23:37
Comment on lines +52 to +61
# Use OrderedDict for the _panels attribute so that items can be efficiently
# removed using FIFO order in the DebugToolbar.store() method. The .popitem()
# method of Python's built-in dict only supports LIFO removal.
# type: ignore[var-annotated]
self._panels = OrderedDict()
while panels:
panel = panels.pop()
self._panels[panel.panel_id] = panel
self.stats: dict[str, Any] = {}
self.server_timing_stats: dict[str, Any] = {}
Copy link
Member

Choose a reason for hiding this comment

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

This feels like there may have been a merge conflict issue.

return getattr(self.request, "csp_nonce", None)

def get_panel_by_id(self, panel_id):
def get_panel_by_id(self, panel_id: str) -> "Panel":
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I'm likely missing something basic. Why can't we use -> Panel since we have the TYPE_CHECKING import check?

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.

Add Type hints to the codebase

3 participants