Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16001 closed Cleanup/optimization (invalid)

template.Context.pop does not behave as dict.pop

Reported by: andrearatto_liste@… Owned by: nobody
Component: Template system Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I don't know if it is worth to change the code, but at least it should be documented with a docstring: one expects Context to be a dictionary like object and in this case the abstraction does not work

Change History (5)

comment:1 by Ramiro Morales, 13 years ago

Resolution: needsinfo
Status: newclosed

What do you expect and what do you get?

comment:2 by anonymous, 13 years ago

Resolution: needsinfo
Status: closedreopened

from django.template import Context
d = {}
t = Context()
dkey = 'val'
tkey = 'val'
d.pop('key')

'val'

t.pop('key')

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: pop() takes exactly 1 argument (2 given)

comment:3 by anonymous, 13 years ago

  • forgot code tags, sorry:
    >>> from django.template import Context
    >>> d = {}
    >>> t = Context()
    >>> d['key'] = 'val'
    >>> t['key'] = 'val'
    >>> d.pop('key')
    'val'
    >>> t.pop('key')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: pop() takes exactly 1 argument (2 given)
    

comment:4 by Dougal Matthews, 13 years ago

Resolution: invalid
Status: reopenedclosed

While I can understand the confusion I think pop and push are described fairly well in the documentation here: http://docs.djangoproject.com/en/1.3/ref/templates/api/#playing-with-context-objects. As described, context objects are stacks. I think this probably covers it in enough detail so closing as invalid.

comment:5 by anonymous, 13 years ago

That's ok, it's mostly cosmetic, but a couple of docstrings would have been good practice, as Context behaves both as a dict and as a list.
I was being scrupulous as the API is usually very intuitive, but this fooled me. bye

Note: See TracTickets for help on using tickets.
Back to Top