Skip to content

Commit 5ff8f0d

Browse files
committed
Merge branch 'main' into dcreager/class-match
* main: Use uv consistently throughout the documentation (#15302) [red-knot] Eagerly normalize `type[]` types (#15272) [`pyupgrade`] Split `UP007` to two individual rules for `Union` and `Optional` (`UP007`, `UP045`) (#15313) [red-knot] Improve symbol-lookup tracing (#14907) [red-knot] improve type shrinking coverage in red-knot property tests (#15297) [`flake8-return`] Recognize functions returning `Never` as non-returning (`RET503`) (#15298) [`flake8-bugbear`] Implement `class-as-data-structure` (`B903`) (#9601) Avoid treating newline-separated sections as sub-sections (#15311) Remove call when removing final argument from `format` (#15309) Don't enforce `object-without-hash-method` in stubs (#15310) Don't special-case class instances in binary expression inference (#15161) Upgrade zizmor to the latest version in CI (#15300)
2 parents 474588c + 5567e7c commit 5ff8f0d

File tree

59 files changed

+2135
-926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2135
-926
lines changed

.github/workflows/build-docker.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ jobs:
4848

4949
- name: Check tag consistency
5050
if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
51+
env:
52+
TAG: ${{ inputs.plan != '' && fromJson(inputs.plan).announcement_tag || 'dry-run' }}
5153
run: |
5254
version=$(grep "version = " pyproject.toml | sed -e 's/version = "\(.*\)"/\1/g')
53-
if [ "${{ fromJson(inputs.plan).announcement_tag }}" != "${version}" ]; then
55+
if [ "${TAG}" != "${version}" ]; then
5456
echo "The input tag does not match the version from pyproject.toml:" >&2
55-
echo "${{ fromJson(inputs.plan).announcement_tag }}" >&2
57+
echo "${TAG}" >&2
5658
echo "${version}" >&2
5759
exit 1
5860
else
@@ -175,6 +177,8 @@ jobs:
175177

176178
- name: Generate Dynamic Dockerfile Tags
177179
shell: bash
180+
env:
181+
TAG_VALUE: ${{ fromJson(inputs.plan).announcement_tag }}
178182
run: |
179183
set -euo pipefail
180184
@@ -195,8 +199,8 @@ jobs:
195199
# Loop through all base tags and append its docker metadata pattern to the list
196200
# Order is on purpose such that the label org.opencontainers.image.version has the first pattern with the full version
197201
IFS=','; for TAG in ${BASE_TAGS}; do
198-
TAG_PATTERNS="${TAG_PATTERNS}type=pep440,pattern={{ version }},suffix=-${TAG},value=${{ fromJson(inputs.plan).announcement_tag }}\n"
199-
TAG_PATTERNS="${TAG_PATTERNS}type=pep440,pattern={{ major }}.{{ minor }},suffix=-${TAG},value=${{ fromJson(inputs.plan).announcement_tag }}\n"
202+
TAG_PATTERNS="${TAG_PATTERNS}type=pep440,pattern={{ version }},suffix=-${TAG},value=${TAG_VALUE}\n"
203+
TAG_PATTERNS="${TAG_PATTERNS}type=pep440,pattern={{ major }}.{{ minor }},suffix=-${TAG},value=${TAG_VALUE}}\n"
200204
TAG_PATTERNS="${TAG_PATTERNS}type=raw,value=${TAG}\n"
201205
done
202206

.github/workflows/publish-docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ jobs:
3333
python-version: 3.12
3434

3535
- name: "Set docs version"
36+
env:
37+
version: ${{ (inputs.plan != '' && fromJson(inputs.plan).announcement_tag) || inputs.ref }}
3638
run: |
37-
version="${{ (inputs.plan != '' && fromJson(inputs.plan).announcement_tag) || inputs.ref }}"
3839
# if version is missing, use 'latest'
3940
if [ -z "$version" ]; then
4041
echo "Using 'latest' as version"

.github/zizmor.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Configuration for the zizmor static analysis tool, run via pre-commit in CI
22
# https://woodruffw.github.io/zizmor/configuration/
3+
#
4+
# TODO: can we remove the ignores here so that our workflows are more secure?
35
rules:
46
dangerous-triggers:
57
ignore:
68
- pr-comment.yaml
9+
cache-poisoning:
10+
ignore:
11+
- build-docker.yml
12+
- publish-playground.yml

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ repos:
9191
# zizmor detects security vulnerabilities in GitHub Actions workflows.
9292
# Additional configuration for the tool is found in `.github/zizmor.yml`
9393
- repo: https://github.com/woodruffw/zizmor-pre-commit
94-
rev: v0.10.0
94+
rev: v1.0.0
9595
hooks:
9696
- id: zizmor
9797

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,21 @@ For more, see the [documentation](https://docs.astral.sh/ruff/).
116116

117117
### Installation
118118

119-
Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI:
119+
Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI.
120+
121+
Invoke Ruff directly with [`uvx`](https://docs.astral.sh/uv/):
122+
123+
```shell
124+
uvx ruff check # Lint all files in the current directory.
125+
uvx ruff format # Format all files in the current directory.
126+
```
127+
128+
Or install Ruff with `uv` (recommended), `pip`, or `pipx`:
120129

121130
```shell
122131
# With uv.
123-
uv add --dev ruff # to add ruff to your project
124-
uv tool install ruff # to install ruff globally
132+
uv tool install ruff@latest # Install Ruff globally.
133+
uv add --dev ruff # Or add Ruff to your project.
125134

126135
# With pip.
127136
pip install ruff

crates/red_knot_python_semantic/resources/mdtest/binary/booleans.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,50 @@ reveal_type(a | b) # revealed: Literal[True]
4646
reveal_type(b | a) # revealed: Literal[True]
4747
reveal_type(b | b) # revealed: Literal[False]
4848
```
49+
50+
## Arithmetic with a variable
51+
52+
```py
53+
a = True
54+
b = False
55+
56+
def lhs_is_int(x: int):
57+
reveal_type(x + a) # revealed: int
58+
reveal_type(x - a) # revealed: int
59+
reveal_type(x * a) # revealed: int
60+
reveal_type(x // a) # revealed: int
61+
reveal_type(x / a) # revealed: float
62+
reveal_type(x % a) # revealed: int
63+
64+
def rhs_is_int(x: int):
65+
reveal_type(a + x) # revealed: int
66+
reveal_type(a - x) # revealed: int
67+
reveal_type(a * x) # revealed: int
68+
reveal_type(a // x) # revealed: int
69+
reveal_type(a / x) # revealed: float
70+
reveal_type(a % x) # revealed: int
71+
72+
def lhs_is_bool(x: bool):
73+
reveal_type(x + a) # revealed: int
74+
reveal_type(x - a) # revealed: int
75+
reveal_type(x * a) # revealed: int
76+
reveal_type(x // a) # revealed: int
77+
reveal_type(x / a) # revealed: float
78+
reveal_type(x % a) # revealed: int
79+
80+
def rhs_is_bool(x: bool):
81+
reveal_type(a + x) # revealed: int
82+
reveal_type(a - x) # revealed: int
83+
reveal_type(a * x) # revealed: int
84+
reveal_type(a // x) # revealed: int
85+
reveal_type(a / x) # revealed: float
86+
reveal_type(a % x) # revealed: int
87+
88+
def both_are_bool(x: bool, y: bool):
89+
reveal_type(x + y) # revealed: int
90+
reveal_type(x - y) # revealed: int
91+
reveal_type(x * y) # revealed: int
92+
reveal_type(x // y) # revealed: int
93+
reveal_type(x / y) # revealed: float
94+
reveal_type(x % y) # revealed: int
95+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Binary operations on classes
2+
3+
## Union of two classes
4+
5+
Unioning two classes via the `|` operator is only available in Python 3.10 and later.
6+
7+
```toml
8+
[environment]
9+
python-version = "3.10"
10+
```
11+
12+
```py
13+
class A: ...
14+
class B: ...
15+
16+
reveal_type(A | B) # revealed: UnionType
17+
```
18+
19+
## Union of two classes (prior to 3.10)
20+
21+
```py
22+
class A: ...
23+
class B: ...
24+
25+
# error: "Operator `|` is unsupported between objects of type `Literal[A]` and `Literal[B]`"
26+
reveal_type(A | B) # revealed: Unknown
27+
```

0 commit comments

Comments
 (0)