Opened 4 years ago

Closed 4 years ago

Last modified 4 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:

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 Changed 4 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

What do you expect and what do you get?

comment:2 Changed 4 years ago by anonymous

  • Resolution needsinfo deleted
  • Status changed from closed to reopened

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 Changed 4 years ago by anonymous

  • 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 Changed 4 years ago by d0ugal

  • Resolution set to invalid
  • Status changed from reopened to closed

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 Changed 4 years ago by anonymous

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