Skip to content

type hints #2654

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

type hints #2654

wants to merge 1 commit into from

Conversation

ElLorans
Copy link
Contributor

@ElLorans ElLorans commented Aug 8, 2025

Partially addresses #2440

  • Re-enable warn_unused_configs in pyproject.toml
  • Re-enable warn_redundant_casts in pyproject.toml
  • Re-enable warn_unused_ignores in pyproject.toml
  • Re-enable strict_equality in pyproject.toml
  • Re-enable strict_concatenate in pyproject.toml
  • Re-enable check_untyped_defs in pyproject.toml

Way too many type: ignore still required, due to highly dynamic dependencies and complex codebase. examples/ had to be modified from kebab-case to snake_case due to mypy requirements.

  • Bonus: run mypy on examples, too
    A simple files = ["flask_admin", "examples"] cannot be used because examples are self contained and use relative imports which do not work from the parent folder.
    The only solution I could find was to add a new step in the tox typing matrix.
[tool.tox.env.typing]
description = "run static type checkers"
dependency_groups = ["typing"]
commands = [
    ["mypy", "--python-version", "3.9"],
    ["mypy", "--python-version", "3.13"],
    ["mypy", "--python-version", "3.9", "--config-file", "examples/mypy-examples-config.toml", "examples", ]

I used a new config file to allow differentiating vs the rest of the repo. Another possibility would be to dump the second config file and explicitate the different options, which right now are:

# this is the difference vs pyproject.toml
# relative imports in examples cause errors when mypy is run from proj folder
ignore_missing_imports = true
disable_error_code = "name-defined" # otherwise flask_sqlalchemy db.Model needs to be ignored, littering examples
warn_unused_ignores = false # otherwise we get conflict with first run of mypy on proj folder

Any feedback on the toml config is welcome.

@ElLorans ElLorans force-pushed the fix/type-hints branch 2 times, most recently from 191ff70 to f46fc01 Compare August 8, 2025 12:22
Copy link
Member

@hasansezertasan hasansezertasan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great effort @ElLorans, thank you 🫶.

@hasansezertasan
Copy link
Member

  • Bonus: run mypy on examples, too
    A simple files = ["flask_admin", "examples"] cannot be used because examples are self contained and use relative imports which do not work from the parent folder.
    The only solution I could find was to add a new step in the tox typing matrix.
[tool.tox.env.typing]
description = "run static type checkers"
dependency_groups = ["typing"]
commands = [
    ["mypy", "--python-version", "3.9"],
    ["mypy", "--python-version", "3.13"],
    ["mypy", "--python-version", "3.9", "--config-file", "examples/mypy-examples-config.toml", "examples", ]

I used a new config file to allow differentiating vs the rest of the repo. Another possibility would be to dump the second config file and explicitate the different options, which right now are:

Just saying, WDYT about uv workspaces? Do you think it would work without a new config file 🤔?

@ElLorans
Copy link
Contributor Author

ElLorans commented Aug 9, 2025

I think uv workspaces solve a different problem. Here, we would need to access each example's folder and run mypy from there (which should be feasible and slightly better than what I opted for)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants