Modernize typing annotations to use PEP 585 built-in generics (Python 3.11)

Hi family,

While reviewing the codebase for Apollo, I noticed several usages of typing.Dict, typing.List, etc., for example:

from typing import Optional, Any, Dict
The project specifies: [pyproject.toml] python = “3.11.*”
So since Python ≥3.9 (PEP 585), built-in collection types support generic annotations directly:

  • dict[str, Any] instead of Dict[str, Any]

  • list[int] instead of List[int]

additionally, Ruff flags this with rule UP035 (deprecated import from typing).

Proposal
We replace deprecated typing generics with modern built-in generics across the codebase.

Currently we are doing it like this;
from typing import Dict
def fn(x: Dict[str, Any]) → Optional[str]:

the proposed one is like this;
def fn(x: dict[str, Any]) → str | None:

Why This Matters

  • Aligns with modern Python typing standards (PEP 585)

  • Removes deprecated typing imports

  • Reduces dependency on legacy constructs

  • Matches Ruff’s recommended style

  • No runtime impact (typing-only change)

  • Safe given Python 3.11 requirement

Have a look at;
Python Software Foundation – PEP 585

Ruff rule UP035

This would be a non-functional refactor (no behavior change), focused purely on type annotations.

I’m happy to work on this if it aligns with the project’s style preferences.

1 Like

Hey @Dhieu

Thanks for reaching out! I’m the maintainer of apollo but I’m not really a python guy. Let me check in with my colleagues on Monday.

It sounds good though - would you be up for raising a PR with a few example changes just so that we can assess the impact? Just spend an hour or so on it?

Thanks @joe
Yes, happy to raise a small PR with a few focused examples so we can evaluate the impact.

1 Like

This will be fantastic to see - thank you!

You’re welcome.
Waiting for your feedback.

Oh! Did you raise a PR on apollo? I can’t see anything over there

Ooops. Sorry my bad.
My mind stack on feedback here with go ahead before raising a PR.
But working on it right now.
Should expect it

1 Like

I see it now - thank you!