Skip to content

Add ruff rules to enforce typing annotations#1197

Open
Lotram wants to merge 2 commits intoGothenburgBitFactory:developfrom
Lotram:better-typing
Open

Add ruff rules to enforce typing annotations#1197
Lotram wants to merge 2 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

Lotram added 2 commits April 7, 2026 19:00
…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
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

return response.json()
else:
# Older python-requests
return response.json
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we constrain requests>=1 in pyproject.toml? (based on first item: https://requests.readthedocs.io/en/stable/api/#migrating-to-1-x)

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