Skip to content

LRUCache's itervalue method should be renamed itervalues #999

@EtiennePelletier

Description

@EtiennePelletier

The LRUCache class in jinja2.utils has a method called itervalue. To be consistent with its functionality and the language as a whole, it should be updated to itervalues.

I don't believe it's ever used in the package and is currently untested (I'm adding a test for it live). To avoid breaking functionality, I believe we should for now create an itervalues method that does the same thing, and add a deprecation warning to itervalue.

Snippet Code

class LRUCache(object):
    """A simple LRU Cache implementation."""

    def items(self):
        """Return a list of items."""
        result = [(key, self._mapping[key]) for key in list(self._queue)]
        result.reverse()
        return result

    def iteritems(self):
        """Iterate over all items."""
        return iter(self.items())

    def values(self):
        """Return a list of all values."""
        return [x[1] for x in self.items()]

    def itervalue(self):
        """Iterate over all values."""
        return iter(self.values())

    def keys(self):
        """Return a list of all keys ordered by most recent usage."""
        return list(self)

    def iterkeys(self):
        """Iterate over all keys in the cache dict, ordered by
        the most recent usage.
        """
        return reversed(tuple(self._queue))

Your Environment

  • Python version: 3.7.3
  • Jinja version: 2.10.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions