def test_util_alias_import() -> None:
    """Importing util from git works, warns, and mypy verifies it and its attributes."""
    # The import should succeed.
    with pytest.deprecated_call() as ctx:
        from git import util

    # There may be multiple warnings. In CPython there will be currently always be
    # exactly two, possibly due to the equivalent of calling hasattr to do a pre-check
    # prior to retrieving the attribute for actual use. However, all warnings should
    # have the same message, and it should be our util-specific message.
    (message,) = {str(entry.message) for entry in ctx}
    assert "git.util" in message, "Has alias."
    assert "git.index.util" in message, "Has target."
    assert "should not be relied on" in message, "Distinct from other messages."

    # As above, we check access through the util alias to the TemporaryFileSwap member.
    from git.index.util import TemporaryFileSwap

    assert_type(util.TemporaryFileSwap, Type[TemporaryFileSwap])

    # This comes after the static assertion, just in case it would affect the inference.
    assert util.TemporaryFileSwap is TemporaryFileSwap
Importing util from git works, warns, and mypy verifies it and its attributes.
test/deprecation/test_toplevel.py