[Django] #32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.

86 views
Skip to first unread message

Django

unread,
Mar 19, 2021, 11:37:13 AM3/19/21
to django-...@googlegroups.com
#32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.
---------------------------------------+---------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: Bug | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Keywords: __repr__
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------+---------------------------
When a partial function is passed as the view, the `__repr__` shows the
`func` argument as `functools.partial` which isn't very helpful,
especially as it doesn't reveal the underlying function or arguments
provided.

Because a partial function also has arguments provided up front, we need
to handle those specially so that they are accessible in `__repr__`.

ISTM that we can simply unwrap `functools.partial` objects in
`ResolverMatch.__init__()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/32572>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 19, 2021, 11:45:02 AM3/19/21
to django-...@googlegroups.com
#32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.
-----------------------------+--------------------------------------

Reporter: Nick Pope | Owner: Nick Pope
Type: Bug | Status: assigned
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:

Keywords: __repr__ | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Nick Pope):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14155 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32572#comment:1>

Django

unread,
Mar 26, 2021, 6:24:13 AM3/26/21
to django-...@googlegroups.com
#32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.
-------------------------------------+-------------------------------------

Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed
Cleanup/optimization |

Component: Core (URLs) | Version: dev
Severity: Normal | Resolution: wontfix

Keywords: __repr__ | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* type: Bug => Cleanup/optimization
* resolution: => wontfix


Comment:

Nick, thanks for this proposition. However I agree with
[https://github.com/django/django/pull/14155/files#r598304014 Tim's
comment], the improvement is not worth the breaking change.

--
Ticket URL: <https://code.djangoproject.com/ticket/32572#comment:2>

Django

unread,
Mar 26, 2021, 11:27:28 AM3/26/21
to django-...@googlegroups.com
#32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.
-------------------------------------+-------------------------------------

Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: new
Cleanup/optimization |

Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:

Keywords: __repr__ | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* status: closed => new
* resolution: wontfix =>


Old description:

> When a partial function is passed as the view, the `__repr__` shows the
> `func` argument as `functools.partial` which isn't very helpful,
> especially as it doesn't reveal the underlying function or arguments
> provided.
>
> Because a partial function also has arguments provided up front, we need
> to handle those specially so that they are accessible in `__repr__`.
>
> ISTM that we can simply unwrap `functools.partial` objects in
> `ResolverMatch.__init__()`.

New description:

When a partial function is passed as the view, the `__repr__` shows the
`func` argument as `functools.partial` which isn't very helpful,
especially as it doesn't reveal the underlying function or arguments
provided.

Because a partial function also has arguments provided up front, we need
to handle those specially so that they are accessible in `__repr__`.

~~ISTM that we can simply unwrap `functools.partial` objects in
`ResolverMatch.__init__()`.~~

--

Comment:

Reopening with a different approach based on my
[https://github.com/django/django/pull/14155#discussion_r602380807
comment].

--
Ticket URL: <https://code.djangoproject.com/ticket/32572#comment:3>

Django

unread,
Mar 26, 2021, 11:53:35 AM3/26/21
to django-...@googlegroups.com
#32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.
-------------------------------------+-------------------------------------

Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |

Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: __repr__ | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => assigned
* stage: Unreviewed => Accepted


Comment:

Improving `__repr__()` sounds good to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/32572#comment:4>

Django

unread,
Mar 29, 2021, 5:31:44 AM3/29/21
to django-...@googlegroups.com
#32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.
-------------------------------------+-------------------------------------

Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |

Component: Core (URLs) | Version: dev
Severity: Normal | Resolution:
Keywords: __repr__ | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32572#comment:5>

Django

unread,
Mar 29, 2021, 6:40:31 AM3/29/21
to django-...@googlegroups.com
#32572: ResolverMatch.__repr__() doesn't handle functools.partial() nicely.
-------------------------------------+-------------------------------------

Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed
Cleanup/optimization |

Component: Core (URLs) | Version: dev
Severity: Normal | Resolution: fixed

Keywords: __repr__ | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed

* resolution: => fixed


Comment:

In [changeset:"41850eec99366a51f98123f7c51e5bc5a8b2798c" 41850eec]:
{{{
#!CommitTicketReference repository=""
revision="41850eec99366a51f98123f7c51e5bc5a8b2798c"
Fixed #32572 -- Improved ResolverMatch.__repr__().

When a partial function was passed as the view, the __repr__() would
show the `func` argument as `functools.partial` which isn't very


helpful, especially as it doesn't reveal the underlying function or
arguments provided.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32572#comment:6>

Reply all
Reply to author
Forward
0 new messages