How to use `typing.Match` and `typing.Pattern`?

How to use typing.Match and typing.Pattern?

They are 'Other concrete types.’ in the typing module.

But neither of these two has actual code implementation. How are they supposed to be used?

As you can see in typing — Support for type hints — Python 3.14.5 documentation, they are deprecated, and you should not use them. They used to be generic versions of re.Pattern and re.Match, and now (since Python 3.9) you can parameterize them directly:

import re

digits: re.Pattern[str] = re.compile("[0-9]+")

def find_digits(s: str) -> list[re.Match[str]]:
    return list(digits.finditer(s))