Skip to content

fix: mypy --strict, back to Python 3.9#7

Open
mjansche wants to merge 1 commit intoabilian:mainfrom
mjansche:dev/mypy
Open

fix: mypy --strict, back to Python 3.9#7
mjansche wants to merge 1 commit intoabilian:mainfrom
mjansche:dev/mypy

Conversation

@mjansche
Copy link

@mjansche mjansche commented Nov 4, 2025

  • Add py.typed.
  • Revert to Union[] for compatibility with Python 3.9.
  • Add type annotations to fix mypy warnings.
  • Passes mypy --strict with Python 3.8 through Python 3.14.

@NickCrews
Copy link
Contributor

This looks good to me!

on main, this test (which doesn't actually exist, but should) actually does already pass:

def test_bogus_conversion():
    """Tests !z errors"""
    value = "Test"
    assert value
    with pytest.raises(SyntaxError):
        t("hello {value!z}")

This raises SyntaxError: Failed to evaluate expression 'value!z': invalid syntax (<string>, line 1). Which isn't the most useful error message. This PR improves on that.

This PR DOES add a bit more runtime overhead to do this check, but I think it is worth the added complexity and perf hit.

@NickCrews
Copy link
Contributor

As a followup, I think I would prefer if we actually added the infrastructure to keep this passing the type checker. Eg we need to set this up with mypy, or actually I might suggest using ty.

@NickCrews
Copy link
Contributor

@sfermigier can you give this a look? If you give a thumbs up I can rebase on main so it is ready to merge

@sfermigier
Copy link
Member

ok.

@NickCrews
Copy link
Contributor

@mjansche our pyproject.toml only says we support python >=3.9. Is there a reason you need to support 3.8? Can you even use this package with 3.8?

@NickCrews
Copy link
Contributor

Also, see this CI run, which runs all the tests and checks on python 3.9. You say Revert to Union[] for compatibility with Python 3.9., but that CI run didn't include that change, and still passed. Am I missing something here, it appears that the code on main still is compatible with 3.9?

@NickCrews NickCrews mentioned this pull request Jan 16, 2026
@NickCrews
Copy link
Contributor

Ah, it may be because of the --strict flag. We don't use that flag in that linked PR. Once that PR is merged, then I will try adding the --strict flag, getting that to pass on just 3.9-3.14, and then I think we should revisit adding support for 3.8

@mjansche
Copy link
Author

@mjansche our pyproject.toml only says we support python >=3.9. Is there a reason you need to support 3.8? Can you even use this package with 3.8?

I don't have a personal reason for using 3.8, but since I was testing my change with different versions, I threw in 3.8 for fun. No need to change the pyrpoject.toml from what it currently is, IMHO.

* Add py.typed.
* Revert to Union[] for compatibility with Python 3.9.
* Add type annotations to fix mypy warnings.
* Passes `mypy --strict src` with Python 3.8 through Python 3.14.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants