When/Why should I init classes outside of __init__? /u/14060m Python Education

Hello all, Thanks in advance.

I’m working on Codecrafter’s http-server project which is Flask at home

I’m feeling great with my request, server, client, and response classes that I made and I decided that I want the user to be able to use decorator functions to define routes like Flask does.

I assessed that I would be wise to wrap them all into a single class so that the user’s main.py isn’t absolutely littered with imports.

I decided that I wanted to take a peek at how Flask is doing things and I noticed that they are instantiating their response and request class just above __init__

Why are they doing this? As I understand it this means that all instances of their Flask class would be reusing the same instance of the response/request class. This seems counterintuitive to me.

https://github.com/pallets/flask/blob/6b054f8f3876ff4c31580b014d344c4cf491059d/src/flask/app.py#L214

TIA

submitted by /u/14060m
[link] [comments]

​r/learnpython Hello all, Thanks in advance. I’m working on Codecrafter’s http-server project which is Flask at home I’m feeling great with my request, server, client, and response classes that I made and I decided that I want the user to be able to use decorator functions to define routes like Flask does. I assessed that I would be wise to wrap them all into a single class so that the user’s main.py isn’t absolutely littered with imports. I decided that I wanted to take a peek at how Flask is doing things and I noticed that they are instantiating their response and request class just above __init__ Why are they doing this? As I understand it this means that all instances of their Flask class would be reusing the same instance of the response/request class. This seems counterintuitive to me. https://github.com/pallets/flask/blob/6b054f8f3876ff4c31580b014d344c4cf491059d/src/flask/app.py#L214 TIA submitted by /u/14060m [link] [comments] 

Hello all, Thanks in advance.

I’m working on Codecrafter’s http-server project which is Flask at home

I’m feeling great with my request, server, client, and response classes that I made and I decided that I want the user to be able to use decorator functions to define routes like Flask does.

I assessed that I would be wise to wrap them all into a single class so that the user’s main.py isn’t absolutely littered with imports.

I decided that I wanted to take a peek at how Flask is doing things and I noticed that they are instantiating their response and request class just above __init__

Why are they doing this? As I understand it this means that all instances of their Flask class would be reusing the same instance of the response/request class. This seems counterintuitive to me.

https://github.com/pallets/flask/blob/6b054f8f3876ff4c31580b014d344c4cf491059d/src/flask/app.py#L214

TIA

submitted by /u/14060m
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *