Live data from Hacker News

Flask 2.0.0 has been merged into master

github.com

41–50 of 55 posts

Re: Flask 2.0.0 has been merged into master

#41

Earlier quoted context omitted.

How Steve Wozniak wrote anything by paper, much less BASIC for the Apple I, is beyond me... He and his kind are in a different reality

Writing code by hand isn't too bad, especially with a good language like LISP. I don't think it requires too much extra effort, just more attention and care as to not make syntax mistakes. With near-instant compile times and auto-linting, we sort of lose the ability to auto-vet code before inputting it.

I think it is a bit deep than that. I love LISP to death but I would never trade a ML language for LISP for writing code that goes into production.

Re: Flask 2.0.0 has been merged into master

#42
post #6

Earlier quoted context omitted.

I've moved most of my Flask projects to Express and NodeJS. Flask was just a PITA to deploy properly in a way that it could handle lots of concurrent connections without a massive memory footprint, and async in Python is a mess. The JS ecosystem has on the other hand moved to async and Promises as the standand/default way to implement things, which makes things much easier. Express middleware is also just easier to w…

You looked into using gevent workers? Sometimes you need to make tweaks to C-based dependencies to make them not block the event loop, but it should work fine for doing a lot of concurrency without a bunch of rewriting. Usually your bottleneck is your database anyway.

How does gevent actually works? It takes care of scheduling and polling?

Re: Flask 2.0.0 has been merged into master

#43

> Add route decorators for common HTTP methods. For example, @app.post("/login") is a shortcut for @app.route("/login", methods=["POST"]). #3907 Why? By default, it’s GET if you don’t specify a method. But now with this change, for special routes such as “/login” it’s POST. IMO these kinds of things make for “gotcha” moments. Just keep defaults simple without special exceptions.

I think you've misread the change, it's nothing to do with login being a special case, it's about moving the HTTP method from the methods argument to the function name.

Re: Flask 2.0.0 has been merged into master

#44

> Drop support for Python 2 Python 3 released on '08. Flask debuted a couple of years later in 2010, on Python 2. 11.5 years later Python 2 is nearly in the rearview. The history of the Python 3 release is surely an impressive one. On a more related note, props to devs/contributors for this release. My experience with Flask was pop-up projects and never mission critical, but i always found it a joy to use and quite i…

You would be surprised by the amount of mission-critical code which runs on Flask. Flask is a great library which gets out of your way - I find it a joy to use compared to Django. Although there are some dark sides, particularly with how Flask interacts with Werkzeug during exceptions when you need CORS (for example, we can't overwrite exception page's Access-Control-Allow-Origin headers with @app.after_request since…

How are these set in werkzeug? Sound like you would be using the werkzeug dev server then...

But this works for me:

    @app.errorhandler(ApplicationError)
    def handle(e):
        resp = e.args[0]
        resp.headers["Access-Control-Allow-Origin"] = "..."
        resp.status_code = 500
        return resp

    @app.route("/err")
    def err():
        raise ApplicationError(jsonify({"reason": "test"}))

Re: Flask 2.0.0 has been merged into master

#45

Earlier quoted context omitted.

You looked into using gevent workers? Sometimes you need to make tweaks to C-based dependencies to make them not block the event loop, but it should work fine for doing a lot of concurrency without a bunch of rewriting. Usually your bottleneck is your database anyway.

How does gevent actually works? It takes care of scheduling and polling?

it uses non-blocking sockets and libev interface to propagate events from the kernel https://sdiehl.github.io/gevent-tutorial/#greenlets

Re: Flask 2.0.0 has been merged into master

#46
post #44

Earlier quoted context omitted.

You would be surprised by the amount of mission-critical code which runs on Flask. Flask is a great library which gets out of your way - I find it a joy to use compared to Django. Although there are some dark sides, particularly with how Flask interacts with Werkzeug during exceptions when you need CORS (for example, we can't overwrite exception page's Access-Control-Allow-Origin headers with @app.after_request since…

How are these set in werkzeug? Sound like you would be using the werkzeug dev server then... But this works for me: @app.errorhandler(ApplicationError) def handle(e): resp = e.args[0] resp.headers["Access-Control-Allow-Origin"] = "..." resp.status_code = 500 return resp @app.route("/err") def err(): raise ApplicationError(jsonify({"reason": "test"}))

I'm aware about the ability to overwrite error handler with a custom code, but Werkzeug's handler already supports pretty stack traces and much more, and I would rather not re-invent the wheel from scratch.

I was talking about using werkzeug's builtin exception handler but with custom headers - which doesn't appear to be supported.

Re: Flask 2.0.0 has been merged into master

#47

> Add route decorators for common HTTP methods. For example, @app.post("/login") is a shortcut for @app.route("/login", methods=["POST"]). #3907 Why? By default, it’s GET if you don’t specify a method. But now with this change, for special routes such as “/login” it’s POST. IMO these kinds of things make for “gotcha” moments. Just keep defaults simple without special exceptions.

"common HTTP methods" meaning GET, POST, PUT, PATCH, DELETE not "/login", etc (those would be routes)

Re: Flask 2.0.0 has been merged into master

#48
post #32

Earlier quoted context omitted.

The main problem is that many Python libraries come in only sync flavor and using them together with asyncio is a pain. NodeJS libraries are almost all standardized to async now. Hell, even Tensorflow.js can give you Promises of computation results.

Seems pretty painless to me: $ python3 -m asyncio >>> from requests import get >>> url = 'https://example.com' >>> response = await asyncio.to_thread(get, url) A lot of Python libraries now offer async APIs, have async support on their short term roadmaps, or other async projects have replaced them.

oh neat! I did not know about asyncio.to_thread; I've been using the longer form thread executor pattern.

Re: Flask 2.0.0 has been merged into master

#49
post #44

Earlier quoted context omitted.

How are these set in werkzeug? Sound like you would be using the werkzeug dev server then... But this works for me: @app.errorhandler(ApplicationError) def handle(e): resp = e.args[0] resp.headers["Access-Control-Allow-Origin"] = "..." resp.status_code = 500 return resp @app.route("/err") def err(): raise ApplicationError(jsonify({"reason": "test"}))

I'm aware about the ability to overwrite error handler with a custom code, but Werkzeug's handler already supports pretty stack traces and much more, and I would rather not re-invent the wheel from scratch. I was talking about using werkzeug's builtin exception handler but with custom headers - which doesn't appear to be supported.

that is not supported. But why would you want to serve that with CORS headers? It's only meant to be displayed in the browser and in dev environment, not production

Re: Flask 2.0.0 has been merged into master

#50
post #43

> Add route decorators for common HTTP methods. For example, @app.post("/login") is a shortcut for @app.route("/login", methods=["POST"]). #3907 Why? By default, it’s GET if you don’t specify a method. But now with this change, for special routes such as “/login” it’s POST. IMO these kinds of things make for “gotcha” moments. Just keep defaults simple without special exceptions.

I think you've misread the change, it's nothing to do with login being a special case, it's about moving the HTTP method from the methods argument to the function name.

Yes I did. Thanks!
Post reply on HN