Skip to content

Conversation

@MeGaGiGaGon
Copy link
Contributor

@MeGaGiGaGon MeGaGiGaGon commented Jul 11, 2025

Summary

Part of #18972

This PR makes non-pep695-type-alias (UP040)'s example error out-of-the-box.

Old example

ListOfInt: TypeAlias = list[int]
PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)])

New example

from typing import Annotated, TypeAlias, TypeAliasType
from annotated_types import Gt

ListOfInt: TypeAlias = list[int]
PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)])

Imports were also added to the "Use instead" section.

Test Plan

N/A, no functionality/tests affected

@AlexWaygood AlexWaygood added the documentation Improvements or additions to documentation label Jul 11, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks!

///
/// ## Example
/// ```python
/// from typing import TypeAlias, TypeAliasType
Copy link
Member

Choose a reason for hiding this comment

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

Let's add the other missing imports too, even if they're not necessary to trigger UP040 out of the box:

Suggested change
/// from typing import TypeAlias, TypeAliasType
/// from typing import TypeAlias, TypeAliasType, Annotated
/// from annotated_types import Gt

And could you also add the missing imports of Annotated and Gt to the Use instead: block below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@AlexWaygood AlexWaygood merged commit dca594f into astral-sh:main Jul 12, 2025
35 checks passed
@MeGaGiGaGon MeGaGiGaGon deleted the patch-2 branch July 12, 2025 17:44
thejchap pushed a commit to thejchap/ruff that referenced this pull request Jul 18, 2025
…19296)

<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

Part of astral-sh#18972

This PR makes [non-pep695-type-alias
(UP040)](https://docs.astral.sh/ruff/rules/non-pep695-type-alias/#non-pep695-type-alias-up040)'s
example error out-of-the-box.

[Old example](https://play.ruff.rs/6beca1be-45cd-4e5a-aafa-6a0584c10d64)
```py
ListOfInt: TypeAlias = list[int]
PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)])
```

[New example](https://play.ruff.rs/bbad34da-bf07-44e6-9f34-53337e8f57d4)
```py
from typing import Annotated, TypeAlias, TypeAliasType
from annotated_types import Gt

ListOfInt: TypeAlias = list[int]
PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)])
```

Imports were also added to the "Use instead" section.

## Test Plan

<!-- How was it tested? -->

N/A, no functionality/tests affected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants