pallets / flask

The Python micro framework for building web applications.

Home Page:https://flask.palletsprojects.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend Config type

Zenthae opened this issue · comments

At the moment, Pylance, when in strict mode, report an error when trying to use app config.
The return type of app.config["KEY"] is Unknown

First time contribution to an open source project, i want to try and see if i can tell Flask to take into account changes made to App.config_class for type hints

Python 3.12

That's because config is a dict-like interface with arbitrary keys and values, so there's no way to say what an arbitrary key's type is. You can probably write a class that uses attribute access or a TypedDict instead to specify the types of known keys, but that only covers the keys you know about, not the extra ones that extensions or applications may use, which is presumably the interesting ones. But subclassing Config to provide other type information shouldn't require anything from Flask itself. You're welcome to explore this, and if you discover that something in Flask is needed, then please open a specific issue about that.