Skip to content

Add ruff rules to enforce typing annotations#1197

Merged
ryneeverett merged 3 commits intoGothenburgBitFactory:developfrom
Lotram:better-typing
Apr 10, 2026
Merged

Add ruff rules to enforce typing annotations#1197
ryneeverett merged 3 commits intoGothenburgBitFactory:developfrom
Lotram:better-typing

Conversation

@Lotram
Copy link
Copy Markdown
Contributor

@Lotram Lotram commented Apr 7, 2026

Add ruff rules ANN to ensure all functions are annotated, improving typing coverage.

First commit enforces this everywhere except services/ ( + docs/ and tests/, already excluded from type checking).

Second commit enforces it in services/__init__.py + 2 services, as an example

@ryneeverett
Copy link
Copy Markdown
Collaborator

Does annotating all functions necessarily improve typing coverage (as enforced by ty)? Doesn't ty complain if it can't infer a type?

@Lotram
Copy link
Copy Markdown
Contributor Author

Lotram commented Apr 8, 2026

Doesn't ty complain if it can't infer a type?

Not really, all missing annotations are replaced by Unknown, an implicit equivalent of Any (see ty doc)

See for example this piece of code:

def f(a):  # expects str
    a.splitlines()


def g():
    b = 5
    return f(b)

without type annotation, ty (as well as pyright and mypy) won't find any issue.

whereas

def f(a: str) -> list[str]:  # expects str
    return a.splitlines()


def g():
    b = 5
    return f(b)

raises an error with both ty and pyright (strangely, mypy does not raise anything with the default config, I haven't investigated)

All type checkers require type annotations to be fully working. Both mypy and pyright have settings to enforce this, Astral uses ruff rules for that

Lotram added 3 commits April 10, 2026 11:36
…otifications.py

- Add type annotations to all functions in the enforced files
- Enforce ruff ANN rules on these files (ignore ANN401 globally)
- Exclude services/, tests/, docs/ from ANN enforcement
Also add annotations for azuredevops and bitbucket, as examples
@ryneeverett ryneeverett merged commit 13dd4f3 into GothenburgBitFactory:develop Apr 10, 2026
7 of 8 checks passed
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.

2 participants