Skip to content

Make Context's repr debug friendly #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

jodal
Copy link
Contributor

@jodal jodal commented Mar 27, 2025

When viewing Contexts in stack traces/debuggers, it was not obvious which context one was looking at, especially if multiple contexts had values of similar types. With this change, the context name is visible in e.g. Django's debug mode exception page.

Since dataclasses are already in use for other classes in htpy, I opted to make the Context class a dataclass too. The constructor should be exactly the same before and after this change.

Before:

<htpy.Context object at 0x7f9af95a16d0>: <<Request: GET '/foo/bar/'> at 0x7f9af5e88410>

After:

Context(name='request', default=<class 'htpy._NO_DEFAULT'>): <<Request: GET '/foo/bar/'> at 0x7fab5e7a6ad0>

When viewing `Context`s in stack traces/debuggers, it was not obvious
which context one was looking at, especially if multiple contexts had
values of similar types. With this change, the context name is visible
in e.g. Django's debug mode exception page.

Since dataclasses are already in use for other classes in htpy, I opted
to make the `Context` class a dataclass too. The constructor should be
exactly the same before and after this change.

Before:

```
<htpy.Context object at 0x7f9af95a16d0>: <<Request: GET '/foo/bar/'> at 0x7f9af5e88410>
```

After:

```
Context(name='request', default=<class 'htpy._NO_DEFAULT'>): <<Request: GET '/foo/bar/'> at 0x7fab5e7a6ad0>
```
@pelme
Copy link
Owner

pelme commented Mar 27, 2025

nice, thanks!

@pelme pelme merged commit 2181290 into pelme:main Mar 27, 2025
14 checks passed
@jodal jodal deleted the jodal/push-nxkxozutyvyz branch March 27, 2025 14:57
pelme added a commit that referenced this pull request Apr 11, 2025
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.

2 participants