Giter VIP home page Giter VIP logo

Comments (3)

davidism avatar davidism commented on June 12, 2024

In general, Python does not do type checking just to show special error messages. If you pass in wrong data to something it might fail in weird ways at a weird spot. This filter isn't special in this regard.

from jinja.

alexharv074 avatar alexharv074 commented on June 12, 2024

@davidism If you look through the code, you have yourself already added a number of FilterArgumentExceptions—correctly, according to good design—to ensure that failures are graceful. Also, the idea that Python programmers normally don't bother to handle their exceptions and just let things blow up confusingly is .... not true.

from jinja.

davidism avatar davidism commented on June 12, 2024

Here's the standard library's own indent function, failing on invalid input without talking about str. Most other functions result in similar behavior. Convince the cpython maintainers that they should add runtime type checks for the arguments of each function they maintain, and I'll consider adding them all over the place in Jinja too.

>>> import textwrap
>>> textwrap.indent({}, "  ")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/textwrap.py", line 488, in indent
    return ''.join(prefixed_lines())
  File "/usr/local/lib/python3.10/textwrap.py", line 486, in prefixed_lines
    for line in text.splitlines(True):
AttributeError: 'dict' object has no attribute 'splitlines'

from jinja.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.