Coder Social home page Coder Social logo

Comments (4)

Changaco avatar Changaco commented on August 16, 2024

Alternatively we could drop support for typecasting, it's seldom used AFAIK, and the current implementation is inefficient.

from aspen.py.

chadwhitacre avatar chadwhitacre commented on August 16, 2024

Without typecasting you have to do the typecasting manually in each simplate. This gets verbose and WET.

/foo/%bar_id.bar/baz.spt
/foo/%bar_id.bar/buz.spt
/foo/%bar_id.bar/biz.spt

Inside each simplate I want a bar object without having to manually call a library function.

Option: typecasters only apply to directory parts, not file parts? Would that work?

from aspen.py.

Changaco avatar Changaco commented on August 16, 2024

In Liberapay we don't use typecasting to handle the /%username/ path segment, we import and call the get_participant function in every simplate. Calling the function explicitly makes it easier to send extra arguments to it. The extra import is a little redundant, but it could be removed by attaching get_participant to the website object. This leads me to the conclusion that builtin support for typecasters is unnecessary.

I think the default typecasters (int and float) could be advantageously replaced by simple helper methods that would be available for both the path and the querystring:

bar_id = request.path.get_int('bar_id', minimum=1)
x = request.path.parse('x', float)
page = request.qs.get_int('page', default=1)

from aspen.py.

chadwhitacre avatar chadwhitacre commented on August 16, 2024

If you want to remove typecasting I won't object. If I ever get to build another Aspen/Pando site and I want typecasters I can bring it back locally as a state chain function. ☺️

from aspen.py.

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.