Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining Python type annotations to build backend #10434

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cthoyt
Copy link
Contributor

@cthoyt cthoyt commented Jan 9, 2025

Summary

This PR add remaining Python type annotations to build backend, specifically in python/uv/_build_backend.py.

Test Plan

  • Running uvx ruff check --select ANN python/ checks that annotations are available everywhere.

    Adding this into ruff.toml would cause all of the scripts to get checked, which I could update if requested, but currently is out of scope for this PR.
  • Running uvx mypy --strict python/ checks that there are no typing issues

@zanieb zanieb requested a review from konstin January 9, 2025 17:39
@zanieb zanieb added the preview Experimental behavior label Jan 9, 2025
@konstin
Copy link
Member

konstin commented Jan 9, 2025

Thanks!

Given that PEP 517 explicitly marks config_settings as escape hatch, with a SHOULD on a string-string multi-dict input, these dicts are either dict[Any, str | list[str]] or dict[Any, Any]. Since we don't read them, i'd go with dict[Any, Any] for simplicity.

@cthoyt
Copy link
Contributor Author

cthoyt commented Jan 9, 2025

@konstin the only issue with dict[Any, Any] is that it requires globally importing (part of) the typing module, even if the type annotation itself is hiding in a string.

Given uv is trying to be as performant as possible, this could be an issue. What do you think?

@notatallshaw
Copy link
Collaborator

Given uv is trying to be as performant as possible, this could be an issue. What do you think?

If your goal is to avoid importing typing at runtime I beleive this is accepted by all type checkers:

TYPE_CHECKING = False
if TYPE_CHECKING:
    from typing import Any

def foo() -> "dict[Any, Any]": ...

@cthoyt
Copy link
Contributor Author

cthoyt commented Jan 9, 2025

Thanks @notatallshaw, I gave that a try and it seemed to work! The results are in 449fa44.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants