pallets / flask

The Python micro framework for building web applications.
https://flask.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
68.18k stars 16.24k forks source link

`Config` `type: ignore` causing downstream error reports #5557

Closed beauxq closed 3 months ago

beauxq commented 3 months ago

The # type: ignore in the code here https://github.com/pallets/flask/blob/8a6cdf1e2a5efa81c30f6166602064ceefb0a35b/src/flask/config.py#L50 is causing type errors to be reported in user code with pyright strict settings.

from flask import Flask

Flask("x").config.update({"A": "3"})  # 'Type of "update" is partially unknown - reportUnknownMemberType'

Based on other typing in the same class, it looks like it could be:

class Config(dict[str, t.Any]):

Environment:

davidism commented 3 months ago

From what I've seen it's pretty much impossible for most libraries to support Pyright in strict mode, therefore it's not a goal. We pass MyPy in strict mode and Pyright in basic mode. That said, we're always open to PRs that improve the typing in a clear and maintainable way.

dict[] is not valid at runtime until Python 3.9. We support Python 3.8 at minimum right now, until it goes EOL. So we'll be able to fix this in a few months, and will automatically know to do so when we run pyupgrade or bump the version checked by the tools.

beauxq commented 3 months ago

class Config(t.Dict[str, t.Any]): would work in Python 3.8

davidism commented 3 months ago

I don't think it's worth the churn if it will be changed again the release after.