pallets/flask

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

beauxq opened this issue · 3 comments

The # type: ignore in the code here

class Config(dict): # type: ignore[type-arg]

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:

  • Python version: 3.12
  • Flask version: 3.0.3

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.

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

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