Giter VIP home page Giter VIP logo

Comments (7)

davidism avatar davidism commented on June 5, 2024

Happy to review a PR, but I don't see what we could do here.

from jinja.

agudallago avatar agudallago commented on June 5, 2024

Handle the AttributeError in a graceful way. Check if the function exists by looking into the dir() list for example.

from jinja.

davidism avatar davidism commented on June 5, 2024

You're asking "detect where an attribute error was raised" which is not trivial, and may not be possible or without other issues. "Just handle it gracefully" isn't really helpful. Again, I'm happy to review a PR, since you seem to know what you're looking for and how to do it.

from jinja.

agudallago avatar agudallago commented on June 5, 2024

except AttributeError:

There you're already handling the AttributeError. What I'm saying is when you handle, you can check if attr is part of obj or not. And then output a different message to the undefined.

Am I being too vague?

from jinja.

davidism avatar davidism commented on June 5, 2024

Yes, I need you to tell me exactly what that code should do to detect this situation.

from jinja.

davidism avatar davidism commented on June 5, 2024

What you're describing is a general issue with Python, it's not possible to tell the difference between and attribute that doesn't exist and a property that raises an AttributeError at runtime without expensive/imperfect introspection. After runtime, when the traceback is built and the frames printed out, you can look backwards and see what actually raised the AttributeError, and know that it's correct. But at runtime that's not viable, examining the stack is expensive and should not be done on every undefined, hasattr has the same problem as getattr, and dir can be overridden or inaccurate (for example, if __getattr__ is defined).

from jinja.

agudallago avatar agudallago commented on June 5, 2024

I understand doing proper introspection is expensive. But how does any extra expensive or imperfect introspection make this a worse user experience than getting a misleading error, if the program anyway is bound to raise an exception that in most programs would actually make your program ends or retries due to invalid arguments (either your html is broken, or. your context is).

I'm not sure how the dir can be inaccurate, you probably know a lot more about Python low level, but to me sounds like a cheap enough thing to check if the attribute is there and would make the error a lot more helpful for the user. And the library is supposed to help the user.

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.