Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Config type #5407

Closed
Zenthae opened this issue Feb 8, 2024 · 1 comment
Closed

Extend Config type #5407

Zenthae opened this issue Feb 8, 2024 · 1 comment

Comments

@Zenthae
Copy link

Zenthae commented Feb 8, 2024

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

@davidism
Copy link
Member

davidism commented Feb 8, 2024

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.

@davidism davidism closed this as completed Feb 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants